PowerShell Transcripts

Do you test cmdlets in a PowerShell window? Do you just do something that you know should work and it doesn’t? Have you ever thrown the kitchen sink at a problem and all of a sudden your script is working? I bet you just closed the PowerShell window you were working in and lost all that work, because I’ve done it before.

Well, once bitten, twice isn’t gonna happen. Why? Because I’ve added the Start-Transcript cmdlet to my profile. It’s that simple, no muss, no fuss. There are a lot of different parameters that you can set with Start-Transcript such as:

  • [-OutputDirectory <String>]
  • [-Append]
  • [-Force]
  • [-NoClobber]
  • [-IncludeInvocationHeader]
  • [-WhatIf]
  • [-Confirm]
  • [[-LiteralPath] <String>]
  • [[-Path] <String>]

I dislike the naming convention that is default with PowerShell so I have added the Start-Transcript with the following bit of code

$a = (Get-Date).ToString(‘Mdy’)

Start-Transcript -Path C:\PowerShell\Transcript\$a”_transcript.txt” -append

What I’m doing is storing the current date in a variable as a string of just the month, day, and year which when you run $a will look something like “4619“, which is April 6th 2019. I then start the transcript with the -path parameter to my powershell\transcript folder with the name 4619_transcript.txt. I also use the -append  parameter in case I quit my powershell session during that day. Using append will just continue with the same transcript and avoid an overwrite of the file or an error.

Overall this is for me is easier to understand and find. I hope this helps you and gives you some idea’s for improvements to what I’ve shown you. Let me know in the comments if you have any enhancements.

New Year Get-Help

This being a new year and not posting in over a year I decided to create a habit of writing once a week about PowerShell, or another technology topic. I have also decided that I am going to focus completely on technology, staying away for all other topics, including family.

Let me state that I am in no way an expert in PowerShell, in fact I’m far from it so I’m learning as you are learning while I write this. I’m doing what Don Jones has talked about in “Be the Master” which is you can be the master by giving back, by writing what you are learning to help other people.

With that, let’s move to the beginning of PowerShell and the best way to learn about cmdlets and how to use them. In fact it’s a cmdlet thats built into PowerShell called “get-help”. That’s easy isn’t it? Well yes, it is, but it is very multifunctional, has many different options, and at times confusing. In this post I’m just going to start with the first basic usage and in the next few posts go into detail. Get-Help in its most basic form without any parameters looks like this using the “get-service” cmdlet:

PS C:\Powershell> get-help get-service


Gets the services on a local or remote computer.

Get-Service [-ComputerName ] [-DependentServices] -DisplayName [-Exclude ] [-Include ]
[-RequiredServices] []

Get-Service [-ComputerName ] [-DependentServices] [-Exclude ] [-Include ] [-InputObject
] [-RequiredServices] []

Get-Service [[-Name] ] [-ComputerName ] [-DependentServices] [-Exclude ] [-Include ]
[-RequiredServices] []

The Get-Service cmdlet gets objects that represent the services on a local computer or on a remote computer, including running
and stopped services.

You can direct this cmdlet to get only particular services by specifying the service name or display name of the services, or
you can pipe service objects to this cmdlet.
Online Version: http://go.microsoft.com/fwlink/?LinkId=821593

To see the examples, type: “get-help Get-Service -examples”.
For more information, type: “get-help Get-Service -detailed”.
For technical information, type: “get-help Get-Service -full”.
For online help, type: “get-help Get-Service -online”

This give you the basics:

  • The Name
  • The Synopsis
  • The Syntax
  • The Description
  • Related Links
  • Remarks

I’m only going to go over the Name, Synopsis and the Remarks in this discussion, with the others in later posts. Let’s start with the obvious “Name”, which is the name of the cmdlet we are getting help on which in this case is “get-service”. Next up is the “Synopsis” which is a brief description of the cmdlet, in this instance get-service “Gets the services on a local or remote computer”. These two are self-explanatory, really not needing any further discussions.

The last part of Get-help that I want to touch on is the “Remarks” because this is a great source of help before you understand the syntax of the cmdlet. By typing a parameter at the end of your get-help cmdlet you can see examples, a detailed view, a full view which is detailed with the addition of input and output object types, and additional notes, and finally the online view which will take you to the docs.microsoft.com page for the cmdlet.

I said finally when I was talking about the online parameter which really isn’t the last way to view help for a cmdlet. The “Show Window” parameter will open a separate window that you can scroll through the help for that cmdlet. It looks like the picture below. I prefer “get-help get-service -ShowWindow” because I get everything in a separate window that I can leave open, and don’t lose anything to the buffer of the PowerShell Window. It also lets me continue to try the cmdlet in various iterations while switching to the window to see the help by itself. Less clutter, easier for myself to work with. You may prefer another parameter like Examples which I use when I really understand the cmdlet, but just want a refresher on the common uses.

That’s the beginning of Get-Help. My next post will start to go into the Description and the Syntax of Get-Help. Let me know in the comments if you have any questions, constructive ideas or tips of your own.

PowerShell: Advanced Profile

In my last post almost 6 months ago I spoke about PowerShell profiles, especially how I preferred a simple profile. If you are just doing some simple things that you need right away or aren’t administering an application like Azure, SharePoint or Office365 then you can suffice with the simple profile. Since I manage Office365 and the applications mentioned above I have morphed to a second profile that I now load to load everything that I need for those applications. The time entering my username and password for those accounts, saves on having to load a different PS1 or create a function to do it later. My thoughts about not creating the function is if I do it once the first time I can just continue working without stopping when I need to do something in those applications.

My previous profile looked like this:

set-location c:\Powershell
$a = (Get-Host).PrivateData
$a.ErrorForegroundColor = “green”

Just your basic profile that sets my default location, and sets the color of the evil error message RED to easier to read GREEN on the blue background. Now for my work within all of the applications that I admin this is the profile I use:

set-location c:\PowerShell
$env:path += “;C:\PowerShell”
$host.ui.RawUI.WindowTitle = “Administrator – Sysadmin Mode”
$Shell = $Host.UI.RawUI
$a = (Get-Host).PrivateData
$a.ErrorForegroundColor = “green”
import-module MSOnline
Import-Module AzureAD
Import-Module AzureADPreview
Import-Module ‘C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell’
$cred = Get-Credential
Connect-MsolService -Credential $cred
Connect-AzureAD -Credential $cred
Connect-SPOService -Url https://company-admin.sharepoint.com -Credential $cred

So, that is a lot more involved, but I only interact with the loading of the profile once at the line: $cred = Get-Credential, which is where I enter my credentials for Office365. Obviously our AzureAD is connected to Office365 which includes our SharePoint too so I only need to enter my credentials once.

First a disclaimer: I close this profile shell when I leave the computer even though I lock the computer screen.  This is best practice so that if anyone gains access to my workstation, they do not gain access to my Sysadmin account in PowerShell to do damage. We change our passwords on a regular basis to prevent access as is also best practice, but anything you can do to lower a hackers attack surface the better.

So, what does this all do? Well that is a pretty good question.

  1. I set the default location of my console as my PowerShell folder that contains all my scripts.
  2. I add the PowerShell folder to the system path
  3. Change the title of the shell to let me know I am running in Sysadmin mode.
  4. Set the system shell as the current console
  5. Set the error color to green
  6. Import all the Modules I need to make sure they do get loaded, including the SharePoint Module that is an MSI install
  7. Store my credentials for this session for use logging in
  8. Connect to all the services using the credentials I supplied. The SharePoint SPOService would need you to replace the word “company” with your company name.


I believe that this front end work saves me a lot of time when I have to do something in SharePoint or the SAAS client or AzureAD.