Category: PowerShell
PowerShell Pack
In case you didn’t know, PowerShell has a pack that offers add-on goodies. Get it at: http://archive.msdn.microsoft.com/PowerShellPack/Release/ProjectReleases.aspx?ReleaseId=3341
PowerShell: Extracting certain lines in any file
I had quite a large file that I needed to parse, and the challenge was to extract certain lines that didn’t match a certain condition. The solution . . . PowerShell, like so: select-string -path filename -notmatch "criteria" | foreach {$_.line} | out-file -filepath filename -encoding ascii That’s it!
PowerShell: Deleting entire lines in a text file based on a partial string match
PS C:\workspace> (gc “fileToParse.txt”) -notmatch "<criteria>" | out-file "resultFile.txt" Note: <Criteria>, for example, “not".
PowerShell: Rename file to lowercase
1. Open PowerShell 2. CD into directory to work on 3. Execute the following command: get-childitem * -recurse | rename-item -newname { $_.name.ToLower() }
PowerShell: Rename file’s file extension
1. Open PowerShell 2. CD into directory to work on 3. Execute the following command: get-childitem * -recurse | rename-item -newname { $_.name -replace ".txt",".bcp" }
Get file version remotely using PowerShell
PS C:\> gc servers.txt | foreach { [system.diagnostics.fileversioninfo]::getversioninfo($_) }