Quantcast
Channel: THWACK: All Content - Server & Application Monitor
Viewing all articles
Browse latest Browse all 12281

SNIPPET: PowerShell Monitors that require a Server Name (Not IP)

$
0
0


I've had all kinds of issues trying to get the computer name from an IP since SAM only sends an IP to the scripts.  I've found a very easy solution to this after picking my brain for WAY too long.  Some PowerShell functions require that you pass the computer name (Exchange being a key player), so getting this information into the script was really important.

 

I used to pull the information from the System Information WMI Class, but that's time consuming and prone to timeouts.

 

Here's what I've done instead:

if ( '${IP}'-like"*.*.*.*" )
{     
$ServerIP='${IP}'
}
else
{
     # Use this IP if this is not being run from within the SAM Script Editor
    $ServerIP="10.5.5.20"
}
$FQDNServerName= ([System.Net.Dns]::GetHostbyAddress($ServerIP)).HostName
$ServerName     =$FQDNServerName.Split(".")[0].ToUpper()


Since I normally use an alternate editor for my PowerShell Scripts (PowerGUI), this was the best way to handle the server name lookup.  It does have a restriction that it uses DNS to handle this lookup.  If you don't have DNS available, you may have to use another method.


Viewing all articles
Browse latest Browse all 12281

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>