-
Notifications
You must be signed in to change notification settings - Fork 11
/
runwinr.ps1
79 lines (66 loc) · 3.1 KB
/
runwinr.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Test WinRM connectivity and configuration
# Created By: Jim Gandy
# v1.0
Function Invoke-RunWinr{
$Name=@{
____ __ ____ __ .__ __. .______
\ \ / \ / / | | | \ | | | _ \
\ \/ \/ / | | | \| | | |_) |
\ / | | | . ` | | /
\ /\ / | | | |\ | | |\ \----.
\__/ \__/ |__| |__| \__| | _| `._____|
}
$Name
# Define the remote computer name
$remoteComputerName = $ENV:ComputerName
$winrmService = Get-Service -Name WinRM -ComputerName $remoteComputerName
$winrmClient = Invoke-Command -ComputerName $remoteComputerName -ScriptBlock { Get-WSManInstance -ResourceURI winrm/config/client }
$winrmListener = Invoke-Command -ComputerName $remoteComputerName -ScriptBlock { Get-WSManInstance -ResourceURI winrm/config/listener -Enumerate}
$winrmEventLog = Get-EventLog System -ComputerName $remoteComputerName -Source Microsoft-Windows-WinRM -ErrorAction SilentlyContinue
$winrmSpn = & setspn -L $ENV:Computername | FindStr /I "WSMAN"
# Initialize an empty object
$resultObject = New-Object PSObject
# Test WinRM service status
if ($winrmService.Status -eq "Running") {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMServiceRunning" -Value $True
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMServiceRunning" -Value $False
}
# Test WinRM listener configuration
if ($winrmListener.Enabled -eq "True") {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMListenerConfigured" -Value $true
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMListenerConfigured" -Value $false
}
# Test WinRM Firewall configuration
if ($winrmListener.Enabled -eq "True") {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMListenerConfigured" -Value $true
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMListenerConfigured" -Value $false
}
# Test WinRM client configuration
if ($winrmClient.NetworkDelayms -eq "5000") {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMClientNetworkDelayms5000" -Value $true
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMClientNetworkDelayms5000" -Value $false
}
# Test network connectivity
if (Test-Connection -ComputerName $remoteComputerName -Count 1 -Quiet) {
$resultObject | Add-Member -MemberType NoteProperty -Name "TestConnectionResult" -Value $true
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "TestConnectionResult" -Value $false
}
# Test event logs for WinRM-related errors or warnings
if ($winrmEventLog.count -gt 0) {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMEventErrors" -Value $True
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WinRMEventErrors" -Value $False
}
# Test WSMAN SPN
if ($winrmSpn.count -ge 2) {
$resultObject | Add-Member -MemberType NoteProperty -Name "WSMAN SPN Count" -Value $True
} else {
$resultObject | Add-Member -MemberType NoteProperty -Name "WSMAN SPN Count" -Value $False
}
$resultObject
}