Ich schreibe ein Skript, um die Pool-Recycling-Parameter von IIS-Servern abzurufen.Powershell invoke-Befehl, der Wert von get-itemproperty nicht zurückgibt
Mein Problem ist, dass lokal der Befehl funktioniert gut (ich das richtige Ergebnis in Minuten):
(Get-ItemProperty "IIS:\AppPools\MyPool" -Name "Recycling.Periodicrestart.Time.Value").totalminutes
Aber wenn die Ferne mit invoke-command
starten, es kommt nichts zurück, Der $RecycleTimeInterval
Wert ist $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
}
}
Beachten Sie, dass der Befehl Get-ChildItem
zum Abrufen der Poolliste einwandfrei funktioniert.