Powershell 调用命令不返回 get-itemproperty 的值

Powershell invoke-command not returning value of get-itemproperty

我正在编写脚本以从 IIS 服务器检索池回收参数。

我的问题是命令在本地运行正常(我在几分钟内得到了正确的结果):

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