I want to get the instanceID of a device just as a string and assign it to a variable
I only know the device name, so when I do:
Get-PnpDevice -FriendlyName 'TSP100'
It displays:
Status Class FriendlyName InstanceId
------ ----- ------------ ------------
OK PrintQueue TSP100 SWD\PRIN...
so ideally it would look something like this:
$env:tsp100id = (Get-PnpDevice -FriendlyName 'TSP100' *some stuff*)
Why not just ask for the property, like this...
Also, just curious. Why are you assigning this as an environment entry?
As for ...
The simplest way in this case is just split on the backslash. For example:
This just says split on the backslash and take action on the last one first.