Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
Powershell 按用户名搜索最终用户的IP地址_Powershell_Powershell 3.0 - Fatal编程技术网

Powershell 按用户名搜索最终用户的IP地址

Powershell 按用户名搜索最终用户的IP地址,powershell,powershell-3.0,Powershell,Powershell 3.0,您好,我正在尝试进行PowerShell搜索,我可以输入最终用户SAMaccountName和it,以推出他们登录的计算机IPv4地址 当试图运行脚本时,它会请求一个类:并且不会为用户提供IPv4地址 $selectUser = Read-Host 'What is the endusers username?' $compname = Get-ADComputer -Filter * -Properties ipv4Address | select Name ForEach($device i

您好,我正在尝试进行PowerShell搜索,我可以输入最终用户SAMaccountName和it,以推出他们登录的计算机IPv4地址

当试图运行脚本时,它会请求一个类:并且不会为用户提供IPv4地址

$selectUser = Read-Host 'What is the endusers username?'
$compname = Get-ADComputer -Filter * -Properties ipv4Address | select Name
ForEach($device in $compname) {
    $usr = Get-WmiObject –ComputerName $device | Select-Object UserName
    if($usr -eq $selectUser){
        $compip = Get-ADComputer -Filter * -Properties ipv4Address | select ipv4Address
    }
}
cmdlet在命令管道位置1获取WMIOObject 提供以下参数的值: 类别:
PS C:\Windows\system32>

正如提示所示,您需要为的
-Class
参数提供一个值;这是必需的。根据您对
用户名
属性的使用情况,您似乎希望

$usr=Get wmioobject–ComputerName$device–Class Win32_ComputerSystem |选择对象用户名
另外,由于使用的(位置)
-Property
参数检索
用户名
属性,
$usr
将不直接包含
用户名
属性,而是包含单个
用户名
属性的对象。以下
if
语句中的条件,
$usr-eq$selectUser
将不会像您预期的那样运行

要解决此问题,请与
$usr.UserName
属性进行比较

if($usr.UserName-eq$selectUser){
或者,要让
$usr
直接存储
用户名
文本,您可以使用
选择对象
-ExpandProperty
参数

$usr=Get WmiObject–ComputerName$device–Class Win32_ComputerSystem |选择对象-ExpandProperty用户名
if($usr-eq$selectUser){
…或使用成员语法检索
用户名
属性

$usr=(Get-WmiObject–ComputerName$device–Class Win32\u ComputerSystem)。用户名
if($usr-eq$selectUser){