Ich verwende das folgende Skript, um eine Liste aller Dienste zu erhalten, die zwar automatisch sind, aber nicht auf einer Reihe von Servern ausgeführt werden.Unterbrechung in Ausgabe in PowerShell entfernt
Code:
$Me = '[email protected]'
function Get-AutoServiceStatus
{
$Servers = 'SRV1', 'SRV2', 'SVR3', 'SVR4'
foreach ($Server in $Servers)
{
Write-Output "`nThe automatic services that aren't running on $Server are:"
Get-WmiObject win32_service -Filter "StartMode = 'auto' AND state != 'Running'" -ComputerName $Server | select -ExpandProperty DisplayName | Format-List
}
}
$Output = Get-AutoServiceStatus | Out-String
$Body = "Hi team,`n`nHere are the services that are set to start automatically on each of the listed servers, but aren't running.`n" + $Output + "Please take the necessary actions.`n`nRegards,`nBig Guy"
Send-MailMessage -From '[email protected]' -To $Me -SmtpServer 'smtpserver.domain.com' -Body $Body -Subject 'Post-reboot service check on Servers'
Console Ausgabe:
The automatic services that aren't running on MySrv are:
Microsoft .NET Framework NGEN v4.0.30319_X86
Microsoft .NET Framework NGEN v4.0.30319_X64
Software Protection
Windows Image Acquisition (WIA)
Empfangene E-Mail:
The automatic services that aren't running on SRV1 are:
Microsoft .NET Framework NGEN v4.0.30319_X86Microsoft .NET Framework NGEN v4.0.30319_X64Software ProtectionWindows Image Acquisition (WIA)
gewünschte E-Mail:
Some friendly text here
The automatic services that aren't running on MySrv are:
Microsoft .NET Framework NGEN v4.0.30319_X86
Microsoft .NET Framework NGEN v4.0.30319_X64
Software Protection
Windows Image Acquisition (WIA)
Bye
Wie in, ich brauche jeden Dienstnamen in einer separaten Zeile angezeigt. Alle Namen der Dienste werden jedoch in derselben Zeile angezeigt.
PS-Version: 3.0
Bitte helfen Sie mir mit diesem. Danke im Voraus!
Grüße,
Ram
Ohne '| Out-String "Ich erhalte das gleiche Ergebnis wie in meinen E-Mails, aber ich addiere' | Out-String "löst das für mich. Ich benutze PS Version 5. –
Haben Sie versucht, stattdessen rn (mit Tick, kann es hier nicht tun)? – majkinetor
@GeraldSchneider Hmm ... Ich habe PS v3. –