Differences
This shows you the differences between the selected revisions of the page.
| 2016-02-23 | 2016-02-23 | ||
| missing -File argument (martin) | using ParseUrl + quoting -text argument + implementig -pause + search is in the *current* directory (martin) | ||
| Line 6: | Line 6: | ||
| <code> | <code> | ||
| - | powershell.exe -File search.ps1 -path "!/" -text !?Text:?! | + | powershell.exe -File search.ps1 -sessionUrl !S -path "!/" -text "!?Text:?!" -pause |
| </code> | </code> | ||
| Line 18: | Line 18: | ||
| <code powershell - SearchText.ps1> | <code powershell - SearchText.ps1> | ||
| # @name &Search for Text... | # @name &Search for Text... | ||
| - | # @command powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -path "!/" -text !?Text:?! -pause | + | # @command powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl !S -path "!/" -text "!?Text:?!" -pause |
| - | # @description Searches recursively for a text in the selected remote directory | + | # @description Searches recursively for a text in the current remote directory |
| # @version 1 | # @version 1 | ||
| param ( | param ( | ||
| + | # Use Generate URL function to obtain a value for -sessionUrl parameter. | ||
| + | $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/", | ||
| [Parameter(Mandatory)] | [Parameter(Mandatory)] | ||
| $path, | $path, | ||
| Line 28: | Line 30: | ||
| $text, | $text, | ||
| $wildcard = "*.*" | $wildcard = "*.*" | ||
| + | [Switch] | ||
| + | $pause = $False | ||
| ) | ) | ||
| Line 37: | Line 41: | ||
| # Setup session options | # Setup session options | ||
| - | $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ | + | $sessionOptions = New-Object WinSCP.SessionOptions |
| - | ·······Protocol = [WinSCP.Protocol]::Sftp | + | ···$sessionOptions.ParseUrl($sessionUrl) |
| - | HostName = "example.com" | + | |
| - | UserName = "user" | + | |
| - | Password = "mypassword" | + | |
| - | SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | |
| - | ····} | + | |
| $session = New-Object WinSCP.Session | $session = New-Object WinSCP.Session | ||
| Line 95: | Line 94: | ||
| } | } | ||
| - | exit 0 | + | $result = 0 |
| } | } | ||
| catch [Exception] | catch [Exception] | ||
| { | { | ||
| Write-Host $_.Exception.Message | Write-Host $_.Exception.Message | ||
| - | exit 1 | + | $result = 1 |
| } | } | ||
| + | |||
| + | # Pause if -pause switch was used | ||
| + | if ($pause) | ||
| + | { | ||
| + | Write-Host "Press any key to exit..." | ||
| + | [System.Console]::ReadKey() | Out-Null | ||
| + | } | ||
| + | |||
| + | exit $result | ||
| </code> | </code> | ||
| Line 108: | Line 116: | ||
| <code powershell> | <code powershell> | ||
| param ( | param ( | ||
| + | # Use Generate URL function to obtain a value for -sessionUrl parameter. | ||
| + | $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/", | ||
| [Parameter(Mandatory)] | [Parameter(Mandatory)] | ||
| $path, | $path, | ||
| Line 113: | Line 123: | ||
| $text, | $text, | ||
| $wildcard = "*.*" | $wildcard = "*.*" | ||
| + | [Switch] | ||
| + | $pause = $False | ||
| ) | ) | ||
| Line 179: | Line 191: | ||
| # Setup session options | # Setup session options | ||
| - | $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ | + | $sessionOptions = New-Object WinSCP.SessionOptions |
| - | ·······Protocol = [WinSCP.Protocol]::Sftp | + | ···$sessionOptions.ParseUrl($sessionUrl) |
| - | HostName = "example.com" | + | |
| - | UserName = "user" | + | |
| - | Password = "mypassword" | + | |
| - | SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | |
| - | ····} | + | |
| $session = New-Object WinSCP.Session | $session = New-Object WinSCP.Session | ||
| Line 203: | Line 210: | ||
| } | } | ||
| - | exit 0 | + | $result = 0 |
| } | } | ||
| catch [Exception] | catch [Exception] | ||
| { | { | ||
| Write-Host $_.Exception.Message | Write-Host $_.Exception.Message | ||
| - | exit 1 | + | $result = 1 |
| } | } | ||
| + | |||
| + | # Pause if -pause switch was used | ||
| + | if ($pause) | ||
| + | { | ||
| + | Write-Host "Press any key to exit..." | ||
| + | [System.Console]::ReadKey() | Out-Null | ||
| + | } | ||
| + | |||
| + | exit $result | ||
| </code> | </code> | ||