Hello all,

I have script which works great, I want to include below condition and it not working

if (Get-PnpDevice -InstanceID 'USB\VID_046D&PID_C52B&MI_02\7&366E4BAA&0&0002') { 'True' } Else { 'False' }

am I doing anything wrong?

3 Spice ups

Not sure this command do not work for me may be you are looking for

$this=Get-PnpDevice -InstanceID 'USB\VID_046D&PID_C52B&MI_02\7&366E4BAA&0&0002'
If($this){
'True'
}
Else{
'False'
}

Try{
Get-PnpDevice -InstanceID 'USB\VID_046D&PID_C52B&MI_02\7&366E4BAA&0&0002' -erroraction  stop
}

Catch{
Write-Warning "$error[0]"
}

same as

if(Test-Path C:\Users){
'True'
}
else{
'False'
}
1 Spice up

If all you’re trying to do is return True or False in your console window, not sure why that won’t work. What result are you getting? What are you expecting to get?

thanks,

I am getting error

"The term ‘Get-PnpDevice’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14

  • Get-PnpDevice <<<<
  • CategoryInfo : ObjectNotFound: (Get-PnpDevice:String) , CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException"

Ohhhh.

Appears this cmdlet is Windows 10+

You’ll need to use WMI instead if you’re not on Win10:

$USBDevice = Get-WmiObject -class Win32_PnPEntity -Namespace "root\CIMV2" | where {$_.PNPDeviceID -eq 'USB\VID_046D&PID_C52B&MI_02\7&366E4BAA&0&0002'}
if ($USBDevice) { 'True' } Else { 'False' }
1 Spice up

I have a feeling you’re right.

OP might be able to get access to this cmdlet by updating Powershell, though:

https://www.microsoft.com/en-us/download/details.aspx?id=54616

1 Spice up