Powershell invoke-command不返回get-itemproperty的值
问题描述:
我正在编写脚本以从IIS服务器中检索池回收参数。Powershell invoke-command不返回get-itemproperty的值
我的问题是,本地命令工作正常(我拿到分钟正确的结果):
(Get-ItemProperty "IIS:\AppPools\MyPool" -Name "Recycling.Periodicrestart.Time.Value").totalminutes
但随着invoke-command
远程启动时,没有回来,该$RecycleTimeInterval
价值$null
:
$PSSession = New-PSSession -ComputerName MyServer
Invoke-Command -Session $PSSession -ScriptBlock {Import-Module WebAdministration}
$PoolArray = Invoke-Command -Session $PSSession -ScriptBlock {Get-ChildItem -Path 'IIS:\AppPools' -Verbose}
ForEach($pool in $PoolArray) {
$PoolName = $pool.Name
$RecycleTimeInterval = Invoke-Command -Session $PSSession -ScriptBlock {(Get-ItemProperty IIS:\AppPools\$args[0] -Name 'Recycling.Periodicrestart.Time.Value').totalminutes} -ArgumentList $PoolName
}
}
请注意,获取池列表的Get-ChildItem
命令正常工作。
答
我已经成功与获得的价值:
$PSSession = New-PSSession -ComputerName MyServer
Invoke-Command -Session $PSSession -ScriptBlock {Import-Module WebAdministration}
$PoolArray = Invoke-Command -Session $PSSession -ScriptBlock {Get-ChildItem -Path 'IIS:\AppPools' -Verbose}
ForEach($pool in $PoolArray) {
$PoolName = $pool.Name
$RecycleTimeInterval = Invoke-Command -Session $PSSession -ScriptBlock {
param($SBPoolName)
(Get-Item IIS:\AppPools\$SBPoolName).Recycling.Periodicrestart.Time.TotalMinutes}
-ArgumentList $PoolName
}
}