Geeks With Blogs

Lance's TextBox

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 }


Posted on Monday, August 25, 2008 5:23 PM PowerShell | Back to top

Comments on this post: test-remotepath.ps1

# re: test-remotepath.ps1
Requesting Gravatar...
Hi, I realize this is outdated, but it seems this doesn't work in the newer version of NetCmdlets that I'm using.
Left by t0ta11ed on Sep 24, 2010 12:58 PM

Your comment:
 (will show your gravatar)

Copyright © Lance Robinson | Powered by: