The Most Important PowerShell Snippet You Will See Today

Don’t worry about what it does, just cut and paste it.

New-Item -ItemType directory -Path $homeDocumentsWindowsPowerShell
Write-Output "Start-Transcript" | Out-File $PROFILE

Just kidding! This is a little snippet of PowerShell code that will set it up so that every time you launch PowerShell it will automatically create a transcript of the session. That way if something goes wrong or unexpectedly right you can look at the transcript later. It also means if a co-worker goes in and breaks stuff with PowerShell without telling you, there is a transcript of what they did.

Here is what it does:

New-Item -ItemType directory -Path $homeDocumentsWindowsPowerShell just creates a new directory in the users Documents folder called WindowsPowerShell.

Write-Output "Start-Transcript" | Out-File $PROFILE just writes the cmdlet Start-Transcript into a file named $PROFILE. PowerShell is hard wired to process this $PROFILE and run whatever commands are in it as a starts.

So that is it, easy but very useful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: