0

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

2
  • 2
    In addition to the provided answer, you can use $tag = (get-ciminstance -classname win32_bios).SerialNumber Commented Mar 7, 2022 at 8:03
  • When I run wmic.exe /? on Windows 10, the message appears "WMIC is deprecated." Use Get-CimInstance. (Get-CimInstance -ClassName Win32_BIOS).SerialNumber Commented Mar 7, 2022 at 16:15

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

sir thanks for your help. have a nice day ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.