-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCheck.ps1
More file actions
55 lines (43 loc) · 1.38 KB
/
ServiceCheck.ps1
File metadata and controls
55 lines (43 loc) · 1.38 KB
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
#// Start of script
#//clear screen
cls
#// input AD
import-module activedirectory;
$servers = get-adcomputer -filter {operatingsystem -like "*server*"};
#// Get year and month for csv export file
$DateTime = Get-Date -f "yyyy-MM-dd"
#//Promt for Tenant
$Tenants = Read-Host -Prompt 'Input Tenant'
#// Set CSV file name
$CSVFile = "C:\Users\Public\$Tenants-"+$DateTime+"-"+"Services Check"+".csv"
#// Create emy array for CSV data
$CSVOutput = @()
foreach ($server in $servers) {
Try{
Write-Host $server.Name
$services = $null;
$services = Get-WmiObject win32_service -computer $server.name -ErrorAction stop | Where-Object {($_.startname -like "*Administrator*")};
}
catch{
Write-Host "failed to connect"
$server |Export-Csv -path C:\Users\Public\$Tenants-Errors.csv -Append
}
if ($services -ne $null) {
foreach ($service in $services) {
write-host $server.name - $service.caption - $service.startname;
}
}
#// Set up hash table and add values
$HashTab = $NULL
$HashTab = [ordered]@{
"Servers" = $server.Name
"Service" = $service.caption
}
$service = $NULL
#// Add hash table to CSV data array
$CSVOutput += New-Object PSObject -Property $HashTab
}
#// Export to CSV files
$CSVOutput | Sort-Object Name | Export-Csv $CSVFile -NoTypeInformation
Invoke-Item C:\users\Public
#// End of script