使用 powershell 和 sccm 从计算机名称中获取用户名

问题描述 投票:0回答:2

我正在尝试执行以下操作:

使用 Powershell 向 SCCM 查询计算机名称,然后在其输出中获取用户名。

现在,我正在使用:

Get-CMDevice -name <computername>

这将返回整个记录。其中有一个名为“UserName”的项目。这就是我要提取的内容。

使用powershell已经有很长时间了,更不用说SCCM插件了。

powershell sccm
2个回答
1
投票

要么使用成员引用运算符(

.
):

(Get-CMDevice -Name AComputerName).UserName

或使用

Select-Object -ExpandProperty

Get-CMDevice -Name AComputerName |Select-Object -ExpandProperty UserName

1
投票

您应该可以将命令放在括号中并直接选择属性,如下所示:

(Get-CMDevice -name <computername>).UserName
© www.soinside.com 2019 - 2024. All rights reserved.