Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I pull the value in Command in Powershell?

I want to learn the powershell version and write conditions accordingly, but I couldn’t do it as I wanted.

"(Get-Host).Version | Select-Object major"

Output:

Major
-----
5

When I use the command, I guess it doesn’t work because it shows as value under major. How can I get the value?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried something like this so I can get it as True or False, but it didn’t work. It always returns false

if ( "(Get-Host).Version | Select-Object major" -eq "5" ) 
{ 
echo "True" 
} 
else 
{ 
echo "False"
 }

Output:

false

>Solution :

Just replace

THIS

if ( "(Get-Host).Version | Select-Object major" -eq "5" ) 
{ 
echo "True" 
} 
else 
{ 
echo "False"
 }

With This:

if ( ((Get-Host).Version).Major -eq "5" ) 
{ 
echo "True" 
} 
else 
{ 
echo "False"
 }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading