Home > Net >  Edit and use powershell output as variable
Edit and use powershell output as variable

Time:03-09

I want to use my pc's ServiceTag as output but i need to delete "SerialNumber" text first.

my code:

cls   
$tag = wmic bios get serialnumber    
$tag

Output:

SerialNumber

JPX9832X31Z

i need JPX9832X31Z as $tag

CodePudding user response:

The easiest solution would be to split the string based on new line and select the 2nd index.

$WMiResult = wmic bios get serialnumber
$tag = ($WMiResult -split "\n")[2]
$tag

Alternatively you can also use Select-Object Cmdlet.

$tag = wmic bios get serialnumber | Select-Object -Index 2
  • Related