我在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}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是将此函数的输出变为变量.下面的内容不起作用......
$ipaddress = (getip)
$ipaddress = getip
set-variable -name ipaddress -value (getip)
Run Code Online (Sandbox Code Playgroud)
任何有关这个问题的帮助将不胜感激.