Mam poniższy kod, który przechodzi i pobiera informacje o zaplanowanych zadaniach i umieszcza dane wyjściowe pojawiające się na ekranie w pliku dziennika.Start-Transcript nie przechwytuje wszystkich danych wyjściowych do pliku dziennika ..?
Zauważyłem jednak, że wszystkie błędy są rejestrowane, Z WYJĄTKIEM dla serwerów, które mają "Odmowa dostępu" - w jaki sposób mogę również zarejestrować te błędy w pliku dziennika.
Poniżej znajduje się kod:
Start-Transcript -path $scheduledpath\logging.txt -append
foreach ($name in $names)
{
Write-Host "Running Against Server $name" -ForegroundColor Magenta
if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue)
{
#$Command = "schtasks.exe /query /S $name /fo CSV /v >c:\tools\Scheduled\$name.csv"
$Command = "schtasks.exe /query /S $name /fo CSV /v >$scheduledpath\$name.csv"
Invoke-Expression $Command
Clear-Variable Command -ErrorAction SilentlyContinue
}
else{
Write-Host "$name is Down" -ForegroundColor Red
}
}
Stop-Transcript
Oto wynik na ekranie:
> Running Against Server SV064909
> SV064909 is Down
> Running Against Server SV081372
> SV081372 is Down
> Running Against Server YBEF008690_vorher_SV064930
> YBEF008690_vorher_SV064930 is Down
> Running Against Server Alt_SV064921
> Alt_SV064921 is Down
> Running Against Server SV073632
> ERROR: Access is denied.
> Running Against Server SV073633
> ERROR: Access is denied.
Oto wynik w pliku dziennika .... no Odmowa dostępu Pokazany .. .?
> Running Against Server SV064909
> SV064909 is Down
> Running Against Server SV081372
> SV081372 is Down
> Running Against Server YBEF008690_vorher_SV064930
> YBEF008690_vorher_SV064930 is Down
> Running Against Server Alt_SV064921
> Alt_SV064921 is Down
> Running Against Server SV073632
> Running Against Server SV073633
aaahhhh ......... interesujące .... dzięki za to ...! – lara400
A teraz link jest zepsuty, a wraz z nim wszystkie obejścia :-( – kroimon
[Resurrected link] (http://web.archive.org/web/20130608164153/http://connect.microsoft.com/PowerShell/feedback/ szczegóły/315875/nie można przechwycić-wszystkie-sesje-wyjściowe-do-transkrypcji) –