我在 powershell 2.0 中有一个名为 getip 的函数,它可以获取远程系统的 IP 地址。
function getip {
$strComputer = "computername"
$colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE"
ForEach ($objItem in $colItems)
{Write-Host $objItem.IpAddress}
}
我遇到的问题是将此函数的输出获取到变量。下面这个不行...
$ipaddress = (getip)
$ipaddress = getip
set-variable -name ipaddress -value (getip)
任何有关此问题的帮助将不胜感激。
也许这会起作用? (如果您使用Write-Host
,数据将被输出,而不是返回)。
function getip {
$strComputer = "computername"
$colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE"
ForEach ($objItem in $colItems) {
$objItem.IpAddress
}
}
$ipaddress = getip
$ipaddress
然后将包含一个字符串 IP 地址数组。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)