mercredi 30 septembre 2020

Simple startswith statment

new to powershell-

Trying get this stupid simple statement working, and I cant understand why it won't output the correct result..

        $asset = "get-wmiobject -class win32_computersystem | select Name"
        if ($asset.StartsWith("ME")) {
        echo "Asset tag is ok" }
        Else 
        { echo "Asset tag needs updating" }

For some reason, despite the result from the WMI query being "ME12345" for example, the startswith code outputs "asset tag needs updating"

Do I need to use a damn /F or something to make the IF statement work with the result from the WMI statement?

Thanks

Aucun commentaire:

Enregistrer un commentaire