<#
.Synopsis
Searches files for pattern, displays matches, opens in text editor.
.Parameter Pattern
Specifies the text to find. Type a string or regular expression.
If you type a string, use the SimpleMatch parameter.
.Parameter Filters
Specifies wildcard filters that files must match one of.
.Parameter Path
Specifies a path to one or more locations. Wildcards are permitted.
The default location is the current directory (.).
.Parameter Include
Wildcard patterns files must match one of (slower than Filter).
.Parameter Exclude
Wildcard patterns files must not match any of.
.Parameter CaseSensitive
Makes matches case-sensitive. By default, matches are not case-sensitive.
.Parameter List
Returns only the first match in each input file.
By default, Select-String returns a MatchInfo object for each match it finds.
.Parameter NotMatch
Finds text that does not match the specified pattern.
.Parameter SimpleMatch
Uses a simple match rather than a regular expression match.
In a simple match, Select-String searches the input for the text in the Pattern parameter.
It does not interpret the value of the Pattern parameter as a regular expression statement.
.Parameter NoRecurse
Disables searching subdirectories.
.Example
C:\PS> Find-Lines 'using System;' *.cs "$env:USERPROFILE\Documents\Visual Studio*\Projects" -CaseSensitive -List
This command searches all of the .cs files in the Projects directory (or directories) and subdirectories,
displays the first matching line of each file with a match, then opens the file to the correct line in the editor.
#>
[CmdletBinding()]Param(
[Parameter(Position=0,Mandatory=$true)][string[]]$Pattern,
[Parameter(Position=1)][string[]]$Filters,
[Parameter(Position=2)][string[]]$Path,
[string[]]$Include,
[string[]]$Exclude,
[switch]$CaseSensitive,
[switch]$List,
[switch]$NotMatch,
[switch]$SimpleMatch,
[switch]$NoRecurse
)
# set up splatting
$lsopt = @{Recurse=!$NoRecurse}
if($Path) { $lsopt.Path=$Path }
if($Include) { $lsopt.Include=$Include }
if($Exclude) { $lsopt.Exclude=$Exclude }
$ssopt = @{'Pattern'=$Pattern}
if($CaseSensitive) { $ssopt.CaseSensitive=$true }
if($List) { $ssopt.List=$true }
if($NotMatch) { $ssopt.NotMatch=$true }
if($SimpleMatch) { $ssopt.SimpleMatch=$true }
# the filter parameter is much faster than the include parameter
Select-String -Path ($( if($Filters) { $Filters|% {ls @lsopt -Filter $_} } else { ls @lsopt } ) |
? {Test-Path $_.FullName -PathType Leaf}) @ssopt |
ogv -p -t "Search: '$Pattern' $Filters" |
% {emeditor $_.Path /l $_.LineNumber} #TODO: customize editor
Brianary
A pedant that hangs out in the dark corner-cases of the web.
Tuesday, May 07, 2013
Find-Lines.ps1
Thursday, April 11, 2013
TLS (HTTPS) query strings: encrypted
- "No URLs, headers or content is visible in the packet trace" ― How Secure Are Query Strings Over HTTPS? | HttpWatch Blog
- "Yes, but" ― ssl - Is an HTTPS query string secure? - Stack Overflow
- True or False: The query string is encrypted in an HTTPS GET request. | mattfleming.com : True
- "…all URL data (with the exception of hostname, which is used to establish the connection) is carried solely within this encrypted connection" ― Google Answers: HTTPS - is URL string itself secure??
- "Conceptually, HTTP/TLS is very simple. Simply use HTTP over TLS precisely as you would use HTTP over TCP." ― RFC 2818 - HTTP Over TLS
| Reactions: |
Wednesday, April 10, 2013
Copy-SchTasks.ps1
A simple PowerShell script to copy scheduled tasks from one machine (often much older) to another.
<#
.Synopsis
Copy scheduled jobs from another computer to this one, using a GUI list to choose jobs.
.Parameter ComputerName
The name of the computer to copy jobs from.
.Parameter DestinationComputerName
The name of the computer to copy jobs to (local computer by default).
#>
[CmdletBinding()]Param(
[Parameter(Mandatory=$true,Position=0)][string]$ComputerName,
[Parameter(Position=1)][Alias('To','Destination')][string]$DestinationComputerName = $env:COMPUTERNAME
)
$TempXml= [io.path]::GetTempFileName()
$CredentialCache = @{}
function Get-CachedCredentials([Parameter(Mandatory=$true,Position=0)][string]$UserName)
{
if(!$CredentialCache.ContainsKey($UserName))
{ $CredentialCache.Add($UserName,(Get-Credential -Message "Enter credentials for $UserName tasks" -UserName $UserName)) }
$CredentialCache[$UserName]
}
function ConvertFrom-Credential([Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]$Credential)
{ $Credential.GetNetworkCredential().Password }
schtasks /query /s $ComputerName /v /fo csv |
ConvertFrom-Csv |
ogv -p -t 'Select jobs to copy' |
select TaskName,'Run As User' -Unique |
% {
schtasks /query /s $ComputerName /tn $_.TaskName /xml ONE |Out-File -Encoding unicode $TempXml
schtasks /create /s $DestinationComputerName /tn $_.TaskName /ru ($_.'Run As User') `
/rp (Get-CachedCredentials $_.'Run As User' |
ConvertFrom-Credential) /xml $TempXml
rm $TempXml
}
$CredentialCache.Clear()
Wednesday, January 23, 2013
Installing to the GAC
Note
|
In earlier versions of the .NET Framework, the Shfusion.dll
Windows shell extension enabled you to install assemblies by dragging them in
File Explorer. Beginning with the .NET Framework 4, Shfusion.dll is
obsolete.
|
Note
|
Gacutil.exe is only for development purposes and should not be
used to install production assemblies into the global assembly cache.
|
(Also: Yikes, there
are multiple GACs (by CLR, and by 32/64-bit processor architecture): .NET
4.0 has a new GAC, why? - Stack Overflow)
Not for VS2012: Visual
Studio setup projects (vdproj) will not ship with future versions of VS - Buck
Hodges - Site Home - MSDN Blogs
Replacement for the alternative: http://wixtoolset.org/
(not http://www.wix.com/)
("Standard
Custom Actions"?):
Tuesday, October 02, 2012
The Ideal Wiki
- A complete, powerful, standard wiki dialect with full HTML5 elements support.
- Easy to modify wiki-wide CSS.
- Good media management for uploading/pasting images and other media content.
- Good table support, including simple native embedded CSV/TSV/PSV/SKV/LOG data, full CALS Table Model support, and numeric/monetary column detection and alignment, leveraging something like accounting.js.
- Support for article tags (keyword metadata), and dynamically-built lists of articles with a given tag.
- Built-in icons or symbols, like Font Awesome.
- Built-in syntax highlighting (like highlight.js).
- Integration with javascript graphing libraries, or text-description-driven diagramming tools, like:
- Modularity for additional extensions and libraries.
- Support for context expiration alerts and requests for review/moderation.
- Full export and a programmable interface to search/read/add/modify/delete articles.
| Reactions: |
Wednesday, September 26, 2012
PowerShell: Get the SSL expiration date from a server
C:\> $req = [Net.HttpWebRequest]::Create('https://www.example.net/')
C:\> $req.GetResponse() |Out-Null
C:\> $req.ServicePoint.Certificate.GetExpirationDateString()
2/20/2014 04:00:00
C:\> 'www.example.org','www.example.com','www.example.net' |
>> % {$req = [Net.HttpWebRequest]::Create("https://$_/")
>> try{$req.GetResponse() |Out-Null}catch{}
>> "$($req.Address.Host): $($req.ServicePoint.Certificate.GetExpirationDateString())"}
>>
www.example.org: 2/20/2014 04:00:00
www.example.com: 1/15/2014 04:00:00
www.example.net: 2/15/2014 16:44:57
Tuesday, May 08, 2012
Updated: Office macro to paste and format TSV text
Outlook (Word) macro to paste TSV text, convert it to a table, then format it using a new style each time.
Sub PasteFormattedTable()
Dim doc As Word.Document
Dim sel As Word.Selection
Dim start As Integer
Set doc = Application.ActiveInspector.WordEditor
Set sel = doc.Windows(1).Selection
start = sel.start
sel.PasteSpecial Link:=False, DataType:=wdPasteText
sel.start = start
sel.ConvertToTable DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
styles = Array(-162, -208, -250, -222, -236, -176, -194)
sel.Style = styles(doc.Tables.Count Mod (UBound(styles) + 1))
End Sub
See Getting Started with VBA in Outlook 2010 to get started.
For more style codes, see Create list of built-in style names.
Subscribe to:
Posts (Atom)
