2016-05-13 74 views
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命令正常工作。

回答

0

我已經成功與獲得的價值:

$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 
    } 
}