test-remotepath.ps1

One of the cmdlets I use most often in my scripts is test-path, which simply tells you whether or not a particular file or path exists.  Below is test-remotepath, which I use to tell me if a remote file or path exists.  This particular script uses get-ftp from NetCmdlets, but it could also just as easily be done with rexec, rshell, or even ssh (sexec).

## test-remotepath.ps1: Tests if a remote file/path exists 
## This script uses ftp to determine whether or not a remote file or path exists.

## This could also easily be done using the invoke-ssh or invoke-rexec, or invoke-rshell

## cmdlets. FTP authentication can also be done with PSCredentials (see other demos)

##

## Returns a boolean.

##

## usage: test-remotepath [-server] <string> [-user] <string> [-password] <string> [-path] <string>

##


param( [string] $server = "",
[string] $user,
[string] $password,
[string] $path )

($results = (get-ftp -server $server -user $user -password $password -path $path)) | out-null
if ($results -eq $null) { return $false }
else { return $true }

 

Print | posted on Monday, August 25, 2008 5:23 PM

Feedback

# re: test-remotepath.ps1

Left by t0ta11ed at 9/24/2010 12:58 PM
Gravatar Hi, I realize this is outdated, but it seems this doesn't work in the newer version of NetCmdlets that I'm using.

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski