2017-07-02 26 views
-2

我有這樣的代碼,當我EXCUTE這個PowerShell代碼:字符串和PowerShell提取用戶名

Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object UserName 

我會得到:

UserName    
--------    
DESKTOP-JBJN9QA\joli 

我怎麼能只提取名稱阿邦 謝謝

+0

'選擇-對象-ExpandProperty UserName' –

回答

2

-Expandproperty UserName不爲我工作 - 如果你不想

Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object PrimaryOwnerName 

嘗試

(Get-CimInstance –ClassName Win32_ComputerSystem).UserName.split('\')[1] 
+0

謝謝很多 其解決 –