Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

I got bored and made a script to see if things are on.

$
0
0

So another post elsewhere asked about taking action through a Powershell script if a VM is offline, I was bored, came up with some solutions but decided I could make it better.

So I created a function called IsItOn

I also didn’t like all the new lines it was creating and wanted it to refresh on the same line.

Well I figured I would share, so here it is.

Function IsItOn{ Param( [Parameter( Mandatory=$True)] [String]$Computer ) While ($true){ if((Test-Connection -ComputerName $Computer -BufferSize 16 -Count 1 -Quiet) -eq $true){ Write-Host "`r$Computer Online " -NoNewline #Padded with a space so it over writes the ending e from the write-host below Start-Sleep 1 } ElseIf((Test-Connection -ComputerName $Computer -BufferSize 16 -Count 1 -Quiet) -eq $false){ Write-Host "`r$Computer Offline" -NoNewline Start-Sleep 1 } }} IsItOn IsItOn 

submitted by /u/admin_all_the_things
[link] [comments]

The post I got bored and made a script to see if things are on. appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images