Powershell invoke命令未返回get-itemproperty的值

Powershell invoke命令未返回get-itemproperty的值,powershell,iis,powershell-remoting,Powershell,Iis,Powershell Remoting,我正在编写一个脚本来从IIS服务器检索池回收参数 我的问题是,该命令在本地运行良好(我在几分钟内得到正确的结果): 但是当使用invoke命令远程启动时,不会返回任何内容,$RecycleTimeInterval值为$null: $PSSession = New-PSSession -ComputerName MyServer Invoke-Command -Session $PSSession -ScriptBlock {Import-Module WebAdministration} $Po

我正在编写一个脚本来从IIS服务器检索池回收参数

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

但是当使用
invoke命令远程启动时,不会返回任何内容,
$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
    }
}

我通过以下方式获得了价值:

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