Quicklinks
NOTE: ActiveXperts Network Monitor ships with a large collection of PowerShell scripts to monitor any aspect of your network. Most PowerShell scripts also have a VBScript implementation. Download Now »
You can use any of the Powershell programs below in ActiveXperts Network Monitor. Click here for an explanation about how to include scripts in ActiveXperts Network Monitor.
################################################################################# # 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 # FileExists.ps1 # Description: # Checks if the specified file exists # Parameters: # 1) strComputer (string) - Hostname or IP address of the computer you want to monitor # 2) strFileName - Path to the file to check # 3) strAltCredentials (string, optional) - Alternate credentials # Usage: # .\FileExists.ps1 "" " " " | <>" # Sample: # .\FileExists.ps1 "localhost" "C:\boot.ini" ################################################################################# # Parameters param ( [string]$strComputer, [string]$strFileName, [string]$strAltCredentials ) cls # Check paramters input if( [string]$strComputer -eq "" -or [string]$strFileName -eq "" ) { echo "UNCERTAIN: Invalid number of parameters - Usage: .\FileExists.ps1 [alt-credentials]" exit } # Create object if( [string]$strAltCredentials -eq "" ) { $objPath = Get-WmiObject -ComputerName $strComputer -Class Win32_OperatingSystem $exists = Test-Path $strFileName } else { $objNmCredentials = new-object -comobject ActiveXperts.NMServerCredentials $strLogin = $objNmCredentials.GetLogin( $strAltCredentials ) $strPassword = $objNmCredentials.GetPassword( $strAltCredentials ) $strPasswordSecure =ConvertTo-SecureString -string $strPassword -AsPlainText -Force $objCredentials = new-object -typename System.Management.Automation.PSCredential $strLogin, $strPasswordSecure $objPath = Get-WmiObject -ComputerName $strComputer -Class Win32_OperatingSystem -Credential $objCredentials //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $exists = Test-Path $strFileName -Credential $objPath } ################################################################################# # THE SCRIPT ITSELF ################################################################################# if( $objPath -eq $null ) { $res = "UNCERTAIN: Unable to connect. Please make sure that PowerShell and WMI are both installed on the monitered system. Also check your credentials" echo $res exit } # Checks for the file existance if(!($exists)) { $res = "ERROR: File " + $strFileName + " does not exist DATA: 0" echo $res } else { $res = "SUCCESS: File " + $strFileName + " exists DATA: 1" echo $res }