Skip to content

Commit 6fa6ff0

Browse files
authored
Add files via upload
1 parent 1ba182c commit 6fa6ff0

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Test_Remote_PS_Connectitvity.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string]$ComputerName
4+
)
5+
6+
Write-Host "Testing WinRM connectivity to $ComputerName..." -ForegroundColor Cyan
7+
8+
# Step 1: Test WinRM service
9+
try {
10+
Test-WSMan -ComputerName $ComputerName -ErrorAction Stop
11+
Write-Host "WinRM service is responding." -ForegroundColor Green
12+
}
13+
catch {
14+
Write-Host "WinRM test failed: $($_.Exception.Message)" -ForegroundColor Red
15+
exit
16+
}
17+
18+
# Step 2: Attempt remote session
19+
Write-Host "`nAttempting remote PowerShell session..." -ForegroundColor Cyan
20+
21+
try {
22+
$session = New-PSSession -ComputerName $ComputerName -ErrorAction Stop
23+
Write-Host "Session created successfully." -ForegroundColor Green
24+
25+
# Step 3: Run a simple command remotely
26+
$result = Invoke-Command -Session $session -ScriptBlock {
27+
hostname
28+
}
29+
30+
Write-Host "`nRemote command executed successfully." -ForegroundColor Green
31+
Write-Host "Remote Hostname: $result"
32+
33+
# Cleanup
34+
Remove-PSSession $session
35+
}
36+
catch {
37+
Write-Host "Remote session failed: $($_.Exception.Message)" -ForegroundColor Red
38+
}

0 commit comments

Comments
 (0)