Hello,
I’m writing a script that will loop through all Exchange Mailbox servers to determine if a particular set of services related to backups are not running. If the services are not running, the script will attempt to start the services and send an email indicating if the services were started or not.
I am getting the following error: “Invoke-Command: Cannot validate argument on parameter ‘Computername’. The argument is null or empty. Provide and argument that is not null or empty, and then try the command again.”
Here’s the script that I created:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 $servers = Get-MailboxServer | sort Name $servicearray = 'sdmgmtsvc','snapdriveservice','snapmanagerservice','swsvc'; foreach ($server in $servers) { $services = Get-Service -ComputerName $servers -Include $servicearray | Format-Table Status,Name,DisplayName,MachineName -AutoSize foreach ($service in $services) { if ($service.status -ne 'Running') { $servername = $service.MachineName $servicename = $service.Name $result = Invoke-Command -ComputerName $servername -ScriptBlock {Start-Service -Include $servicename} -ArgumentList $servicename if ($result -match "Service Started") { $body = "Started $servicename on $servername" $from = "noreply@domain.com" $to = "username@domain.com" $subject = "SnapDrive and SnapManger Service Alert" $smtpserver = "servername@domain.com"} if ($result -match "Service Failed to Start") { $body = "Failed to Start $servicename on $servername. Please start $servicename to ensure backup jobs execute." $from = "noreply@domain.com" $to = "username@domain.com" $subject = "SnapDrive and SnapManger Service Alert" $smtpserver = "servername@domain.com"} if ($body) { Send-MailMessage -From $from -To $to -Subject $subject -Body $body -SmtpServer $smtpserver -BodyAsHtml} } } }
Thanks,
Richard