-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckServicesAndStartThem.ps1
27 lines (25 loc) · 1.13 KB
/
CheckServicesAndStartThem.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$Username = "username"
$Password = ConvertTo-SecureString 'password' -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
$comps=Get-Content -Path "C:\ops\comps.csv"
foreach ($c in $comps){
Write-Host $c
Invoke-Command –ComputerName $c -Credential $Credential -ScriptBlock{
function Get-ServiceLogonAccount {
[cmdletbinding()]
param (
$ComputerName = $env:computername,
$LogonAccount
)
if($logonAccount){
$stopped = Get-WmiObject -Class Win32_Service -ComputerName $ComputerName | ? { $_.StartName -match $LogonAccount } | Where-Object {$_.State -eq "Stopped"} | select DisplayName, StartName | Format-Table
$stopped
Start-Service -DisplayName "servicename1", "servicename2"
}
else{
Get-WmiObject -Class Win32_Service -ComputerName $ComputerName | select DisplayName, StartName, State
}
}
Get-ServiceLogonAccount -LogonAccount accountname
}
}