0
Warum bekomme ich eine leere Datei, wenn ich dieses Skript TEE-Object ausgegeben habe, sehe ich die Ausgabe auf dem Bildschirm?Leere Datei in Tee-Objekt Datei Powershell
$Computers = (gc C:\Scripts\Computers.txt)
foreach ($Computer in $Computers)
{
$Computer
Invoke-Command -ComputerName $Computer -ScriptBlock { winmgmt -standalonehost }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "UALSVC" -ErrorAction SilentlyContinue){ Stop-Service UALSVC -Force } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "MMS" -ErrorAction SilentlyContinue){ Stop-Service MMS -Force } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "iphlpsvc" -ErrorAction SilentlyContinue){ Stop-Service iphlpsvc -Force } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "hpqams" -ErrorAction SilentlyContinue){ Stop-Service hpqams -Force } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "wscsvc" -ErrorAction SilentlyContinue){ Stop-Service wscsvc -Force } }
Invoke-Command -ComputerName $Computer -ScriptBlock { Restart-Service winmgmt -Force }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "hpqams" -ErrorAction SilentlyContinue){ Start-Service hpqams } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "iphlpsvc" -ErrorAction SilentlyContinue){ Start-Service iphlpsvc } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "MMS" -ErrorAction SilentlyContinue){ Start-Service MMS } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "UALSVC" -ErrorAction SilentlyContinue){ Start-Service UALSVC } }
Invoke-Command -ComputerName $Computer -ScriptBlock { if (Get-Service "wscsvc" -ErrorAction SilentlyContinue){ Start-Service wscsvc } }
} Tee-Object -file c:\Scripts\WMI-Output.txt
'& {foreach (...) {...}} | Tee-Objekt ... ' – PetSerAl
Perfekt, danke! – pinchepooch
Nur eine Beobachtung - die gesamte Dienstmanipulation konnte über RPC mit dem Parameter -ComputerName von Get-Service/Stop-Service/Start-Service durchgeführt werden. –