September 18th, 2019

PowerTip: Identify which Platform PowerShell is running on

Doctor Scripto
Scripter

Summary: Using $PSVersionTable to identify if you are on Windows or Unix

A picture containing scissors

Description automatically generated

Hey, Doctor Scripto! I’m working on my PowerShell scripts and I need to be able to identify if I’m working on Windows or Linux. How can I do this easily?

No problem at all and glad to help. Just examine the $PSVersionTable property called Platform. It will contain one either ‘Unix’,’Win32NT’ on PowerShell Core. In the case of Windows PowerShell it will not exist.

$PSVersionTable.Platform

PowerShell, Doctor Scripto, PowerTip, Sean Kearney

 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • John J. Kavanagh

    I like the isWindows, isLinux, isMacOS variables but this is a nice one.