tftp.ps1 - powershell script by ActiveXperts Software
tftp.ps1 checks for file existence on a TFTP host.
Use tftp.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select tftp.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
tftp.ps1 script code
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com ################################################################################# # Script # Tftp.ps1 # Description: # Check for file existence on a TFTP host # This function uses ActiveXperts Network Component. # ActiveXperts Network Component is automatically licensed when ActiveXperts Network Monitor is purchased. # For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component # Declare Parameters: # 1) strHost (string) - Host name or IP address of the TFTP host # 2) strFile (string) - The file to check # Usage: # .\Tftp.ps1 '<Hostname | IP>' '<File>' # Sample: # .\Tftp.ps1 'srv202.activexperts-labs.com' '/network-monitor/readme.txt' ################################################################################# # -- Declare Parameters param( [string]$strHost = '', [string]$strFile = '' ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Validate parameters, return on parameter mismatch if( $strHost -eq '' -or $strFile -eq '' ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\Tftp.ps1 "<Hostname | IP>" "<filename>"' echo $res exit } # Declare local variables by assigning an initial value to it $objTftpServer = new-object -comobject AxNetwork.TftpServer # Use default port 69 $objTftpServer.HostPort = 69 # Create a temp file to download file to $objFileSystem = new-object -comobject Scripting.FileSystemObject $strTempFile = $objFileSystem.GetSpecialFolder(2).Path $strTempFile += '\' $strTempfile += $objFileSystem.GetTempName() # Get file $objTftpServer.Get( $strHost,$strFile,$strTempFile ) if ( $objTftpServer.LastError -eq 0 ) { $res = 'SUCCESS: File [' + $strFile + '] found on TFTP host [' + $strHost + ']; size=[' + $objTftpServer.BytesReceived + ' bytes]' echo $res } else { $res = 'ERROR: File [' + $strFile + '] not found on TFTP host; result=[' + $objTftpServer.LastError + '; ' + $objTftpServer.GetErrorDescription($objTftpServer.LastError) + ']' echo $res } if( $objFileSystem.FileExists( $strTempFile ) ) { $objFileSystem.DeleteFile( $strTempFile ) } exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }