# Get the directory where the script is located $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition # Path to the server list file $serverListPath = Join-Path $scriptDir "servers.txt" # Prompt for username and credentials $username = Read-Host "Enter the username (e.g., DOMAIN\user or user@domain.com)" $cred = Get-Credential -UserName $username -Message "Enter the password for $username" # Services to check and start $services = @("wuauserv", "bits", "cryptsvc", "trustedinstaller") # Read server names from file $servers = Get-Content -Path $serverListPath foreach ($server in $servers) { Write-Host "`n--- Processing $server ---" -ForegroundColor Cyan foreach ($service in $services) { try { # Get service status remotely $svcStatus = Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock { param($svcName) $svc = Get-Service -Name $svcName -ErrorAction Stop return @{ Name = $svc.DisplayName; Status = $svc.Status } } -ArgumentList $service Write-Host "Service: $($svcStatus.Name)" Write-Host " Status: $($svcStatus.Status)" # Start the service if it's stopped if ($svcStatus.Status -eq 'Stopped') { Write-Host " Starting $service on $server..." Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock { param($svcName) Start-Service -Name $svcName } -ArgumentList $service Write-Host " $service started successfully." -ForegroundColor Green } else { Write-Host " $service is already running." } } catch { Write-Host " Error with $service on $server: $_" -ForegroundColor Red } } }