Quantcast
Channel: Automate IT! » kollegaru
Viewing all articles
Browse latest Browse all 41

Powershell notes. Part 1

$
0
0

All outputs to file

In one of days i was creating migration script and thought about the way how to put error output and all PS messages to one system file. I knew about Write-Host and Write-Output file, but never thought about redirecting all output threads to file.

Solution can vary:

  • In powershell 2.0 you need to run script with separate powershell command
  • powershell myScript.ps1 > $somefile

    Don’t try to use start-transcript command. It does not record Write-Error, Write-Verbose, or Write-Debug...only standard output. ("The transcript includes all command that the user types and all output that appears on the console"). “Tee” command doesn’t redirect warning stream.

  • In powershell 3.0 you can use separate streams for each type of information:
In PS 3.0, we've extended output redirection to include the following streams:
 Pipeline (1)
 Error    (2)
 Warning  (3)
 Verbose  (4)
 Debug    (5)
 All      (*)

Some scenarios of usage for PS 3.0 are described here: http://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=297055 

Some links:

Regular expressions

One of point i would like to mention here is case sensitivity. Usually regular expressions are case sensitive by default (even in .NET framework ) . However, it is not true in PowerShell. -match and -replace are case insensitive, as are -imatch and -ireplace.



Viewing all articles
Browse latest Browse all 41

Latest Images

Trending Articles





Latest Images