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

Save powershell get-disk as variable and the use it in if function

I want to make script run only from a specific usb drive. I want to make variable $drive which has output of get-disk command, and the, if $drive contains my usb serial – make some function.

$drive=get-disk -SerialNumber "980D06056030" | ft SerialNumber

if ( "980D06056030" -eq $drive ) {Write-Host "Yes"}

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

This doesn`t work =(

>Solution :

You should use SerialNumber property like this.

$drive = (get-disk -SerialNumber "980D06056030").SerialNumber
 if ( "980D06056030" -eq $drive ) {Write-Host "Yes"}
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