小编tom*_*mmy的帖子

powershell函数输出到变量

我在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)

任何有关这个问题的帮助将不胜感激.

powershell powershell-2.0

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

powershell ×1

powershell-2.0 ×1