Ich versuche, Powershell-Skript ausführen, um den Status des Anwendungspools zu erhalten. Aber ich bekomme unter Fehler. Kann mir bitte jemand hier helfen was ich vermisse?Fehlende 'in' nach Variable in foreach Schleife
Code:
import-module webadministration
$applicationPools = Get-ChildItem IIS:\AppPools
ForEach ($_.name in $applicationPools)
{
$appPool = $_.name
$appmemversion = get-ItemProperty "IIS:\AppPools\$appPool" ManagedRuntimeVersion.value
$appmem = get-ItemProperty "IIS:\AppPools\$appPool" recycling.periodicrestart.privateMemory.value
$apptimeinv = get-ItemProperty "IIS:\AppPools\$appPool" recycling.periodicRestart.time | select-object value
$appsettime = get-ItemProperty "IIS:\AppPools\$appPool" Recycling.periodicRestart.schedule.collection[0].value | select-object value
Write-Output "$appPool,$appmemversion,$appmem,$apptimeinv,$appsettime,"
}
Fehler:
+ ForEach ($_.name in $applicationPools)
+ ~
Missing 'in' after variable in foreach loop.
At C:\Users\JoyMathew\Desktop\App.ps1:9 char:38
+ ForEach ($_.name in $applicationPools)
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingInInForeach
Regads, Joy
$ _ wird in Pipelines verwendet ... Sie haben die $ -Anwendungspools von der foreach-Schleife getrennt, wenn Sie den Namen $ _. In einen Variablennamen wie $ pool ändern, der Ihr Problem beheben sollte. –
@thomschumacher Sie sollten eine Antwort geben und ein kurzes Beispiel für korrigierten Code geben. – TheMadTechnician
Ich habe versucht, $ ($ _. Name) einzupacken, aber ich bekomme immer noch denselben Fehler. –