News

 Subscribe Add to Technorati Favorites

 

 

 

 


 

 

Search My Blog:

 

 

My Stats

  • Posts - 472
  • Comments - 277
  • Trackbacks - 265

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Blogs


Miscellanous


Noteworthy Stuff


Popular Posts



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 @ Monday, August 25, 2008 5:23 PM | Filed Under [ PowerShell ]

Comments

No comments posted yet.
Post a comment





 

Please add 6 and 4 and type the answer here: