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