1
我正在編寫腳本以從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
命令正常工作。