Thursday, August 8, 2024

Outputting Everything that was Written on Screen in Powershell

Today, I was writing a script that showed a lot of output in the screen.  I then decided that it was a good idea to just save the output to a file as this output will be sent to people via email.  I didn't want to use Out-File on every single Write-Output that I wrote.  I ended up using Start-Transcript and Stop-Transcript instead.  I think it actually worked well.

This is what I used.

Start-Transcript -Path $outputFile -UseMinimalHeader
Write-Output ""

....

Write-Output ""
Stop-Transcript



The output file would look like this.


**********************
PowerShell transcript start
Start time: 20240808083029
**********************
Transcript started, output file is C:\Users\WindowsUserID\Downloads\DB_Users_and_Permissions_DBNAME_20240808.txt

....


**********************
PowerShell transcript end
End time: 20240808083033
**********************






Little script to see the backup history

 Today, I was teaching a co-worker how to create a copy only backup of a SQL Managed Instance database.  And I came up to use this script t...