2016-05-13 3 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 
    } 
}