Powershell: Check Version Before Running Script

Powershell: Check Version Before Running Script

If you create a PowerShell script and we say it must be version 3.0, you can simply add this to your script:

If ((Get-Host).Version.Major.Equals(3))
{
#Your script will run here.
}
Else
{
#You can add an error message here, so the user will understand, he/she doesn't have the actual version.
}


Remember, you can not use If ((Get-Host).Version.Major = "3") or something like that, because "Major" is a locked property.
Leave a Comment
  • Please add 8 and 8 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 4. Comment: Modified title

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Good one. Ciminstance is worked from PS version 3 & above. :)

  • Richard Mueller edited Revision 4. Comment: Modified title

Page 1 of 1 (2 items)