Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 字符串和powershell从数组中提取用户名_String_Powershell - Fatal编程技术网

String 字符串和powershell从数组中提取用户名

String 字符串和powershell从数组中提取用户名,string,powershell,String,Powershell,我有此代码,当我执行此powershell代码时: Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object UserName 我会得到: UserName -------- DESKTOP-JBJN9QA\joli 我怎样才能只提取joli这个名字 谢谢你-Expandproperty用户名对我不起作用-如果你不想 Get-CimInstance –Class

我有此代码,当我执行此powershell代码时:

Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object UserName 
我会得到:

UserName               
--------               
DESKTOP-JBJN9QA\joli
我怎样才能只提取joli这个名字
谢谢你

-Expandproperty用户名
对我不起作用-如果你不想

Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object PrimaryOwnerName
试一试


选择对象-ExpandProperty用户名
(Get-CimInstance –ClassName Win32_ComputerSystem).UserName.split('\')[1]