Berke the Vulpes
Berke the Vulpes

Reputation: 65

Edit and use powershell output as variable

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

Upvotes: 0

Views: 707

Answers (1)

user459872
user459872

Reputation: 24897

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

Upvotes: 1

Related Questions