forked from officecigar/windows_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop-services_different_servers.ps1
55 lines (42 loc) · 1.69 KB
/
stop-services_different_servers.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
Gets COMPUTER stop different services(s) on differentserver(s) !!! FUN STUFF
.EXAMPLE
'one', 'two', 'three' stop-different_services_different_servers.ps1
.EXAMPLE
stop-different_services_different_servers.ps1 -computername localhost
.EXAMPLE
stop-different_services_different_servers.ps1-computername one, two, three
.EXAMPLE
get-content <ServerList.txt> or <ServerList.csv> | Netwmi.ps1
.PARAMETER computername
one or more computername, or IP address... peace to America!
#>
[cmdletbinding()]
Param(
[Parameter (Mandatory=$true,ValuefromPipeline=$true)]
[string []]$computername,
[string]$errorlogpath ='c:\temp\stopservice_errors.log'
)begin{
$host.UI.RawUI.WindowTitle = "Stop different a service on servers"
import-Module ActiveDirectory
}
process{
foreach ($computer in $computername) {
Write-Verbose "about to query $computer"
try {
$IDExist =$true
$who = Get-WMIObject Win32_ComputerSystem -computername $computer| Select-Object -ExpandProperty name
$who
$service = Read-Host "Enter name of service"
Get-Service -ComputerName $computer -Name $service | stop-Service
$service
} catch {
$IDExist = $false
Write-Verbose "$computer failed wrting to $errorlogpath "
Write-Verbose " Error was $MyErr"
$computer | Out-File $errorlogpath -append
}
}
}
end{}