Created
May 27, 2024 13:19
-
-
Save adbertram/e2a675e3c3f248f1a0325af1e9a9b673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a custom object for a server or whatever object you want | |
$server = [pscustomobject]@{ | |
Name = "Server1" | |
IPAddress = "192.168.0.1" | |
} | |
# Add a ScriptMethod to check if the server is online | |
## This can run any code you may like to associated with an object | |
$server | Add-Member -MemberType ScriptMethod -Name "IsOnline" -Value { | |
param ($Timeout = 1000) | |
Test-Connection -ComputerName $this.IPAddress -Count 1 -Quiet | |
} | |
## Call the script method | |
$server.IsOnline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment