PowerShell

Comparing Variables in Windows PowerShell and PowerShell 7

PowerShell automatic variables are stored and maintainanced by PowerShell. This applies to Windows PowerShell that is shipped with every Windows operating system as well as PowerShell downloaded via GitHub.

In this blog post I am going to show how to compare automatic variables in Windows PowerShell and PowerShell 7.

For instance, the $IsWindows variable is missing in Windows PowerShell. It would also make no sense to check whether Windows is installed or not, because Windows PowerShell only runs on Windows OS.


$IsWindows

1.PNG

But there are more differences we will discover now.

Saving Varialbes in a File

First we save the list of the Windows PowerShell variables in a file.


Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\windowspowershellvariables.txt

Unbenannt.PNG

Then we save the PowerShell variables in a file.


Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\powershellvariables.txt

1.PNG

Comparing Variables of Windows PowerShell and PowerShell

Here is the list showing us the differences:


Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt)

Unbenannt.PNG

To see what Windows PowerShell is missing compared to PowerShell run


(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "=>"} |
Select-Object -ExpandProperty InputObject) -join ", "

Unbenannt.PNG

To see what PowerShell is missing compared to Windows PowerShell run


(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "<="} |
Select-Object -ExpandProperty InputObject) -join ", "

Unbenannt.PNG

Well, task accomplished. Hope that was informative, especially for those readers who often work with automatic variables.

See you next time with PowerShell!

Categories: PowerShell

Tagged as: ,

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 )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.