__GENUS : 2\n__CLASS : Win32_BIOS\n__SUPERCLASS : \n__DYNASTY : \n__RELPATH : \n__PROPERTY_COUNT : 1\n__DERIVATION : {}\n__SERVER : \n__NAMESPACE : \n__PATH : \nSerialNumber : AJRYTS1\nPSComputerName : \n<\/code><\/pre>\nHow can I filter that to just give the serial number as in example one?<\/p>","upvoteCount":6,"answerCount":12,"datePublished":"2014-10-14T20:35:30.000Z","author":{"@type":"Person","name":"bloodhoundgang","url":"https://community.spiceworks.com/u/bloodhoundgang"},"acceptedAnswer":{"@type":"Answer","text":"
try:<\/p>\n
get-wmiobject -class win32_bios -property serialnumber |fl Serialnumber\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2014-10-14T20:38:39.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/2","author":{"@type":"Person","name":"Gary-D-Williams","url":"https://community.spiceworks.com/u/Gary-D-Williams"}},"suggestedAnswer":[{"@type":"Answer","text":"What I’m trying to do is a wmi query for the serial number that only returns the serial number. Using wmic it would look like this;<\/p>\n
wmic bios get serialnumber\n<\/code><\/pre>\nIt would return this;<\/p>\n
AJRYTS1\n<\/code><\/pre>\nIn PS this is what I use;<\/p>\n
get-wmiobject -class win32_bios -property serialnumber\n\n<\/code><\/pre>\nThis is what is returned;<\/p>\n
__GENUS : 2\n__CLASS : Win32_BIOS\n__SUPERCLASS : \n__DYNASTY : \n__RELPATH : \n__PROPERTY_COUNT : 1\n__DERIVATION : {}\n__SERVER : \n__NAMESPACE : \n__PATH : \nSerialNumber : AJRYTS1\nPSComputerName : \n<\/code><\/pre>\nHow can I filter that to just give the serial number as in example one?<\/p>","upvoteCount":6,"datePublished":"2014-10-14T20:35:30.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/1","author":{"@type":"Person","name":"bloodhoundgang","url":"https://community.spiceworks.com/u/bloodhoundgang"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Gary D Williams:<\/div>\n
\ntry:<\/p>\n
get-wmiobject -class win32_bios -property serialnumber |fl Serialnumber\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nFormat-list. Excellent. You da man. THX<\/p>","upvoteCount":0,"datePublished":"2014-10-14T20:41:55.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/3","author":{"@type":"Person","name":"bloodhoundgang","url":"https://community.spiceworks.com/u/bloodhoundgang"}},{"@type":"Answer","text":"
I wish they would put an alias for the class. EG… “32_” or “64_” Maybe something along those lines…<\/p>\n
Thanks for the super fast response Gary.<\/p>","upvoteCount":0,"datePublished":"2014-10-14T20:44:45.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/4","author":{"@type":"Person","name":"bloodhoundgang","url":"https://community.spiceworks.com/u/bloodhoundgang"}},{"@type":"Answer","text":"
Got a, probably not for you, more complicated one. Multiple queries. Would you like it in a new thread?<\/p>","upvoteCount":0,"datePublished":"2014-10-14T20:47:23.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/5","author":{"@type":"Person","name":"bloodhoundgang","url":"https://community.spiceworks.com/u/bloodhoundgang"}},{"@type":"Answer","text":"
I would recommend using Select-Object vs Format-Table as it keeps objects in the pipeline as objects vs formatting into a table which is only good for displaying in console<\/p>\n
Get-WMIObject Win32_Bios | Select SerialNumber\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2014-10-14T22:52:02.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/6","author":{"@type":"Person","name":"brian-duffy","url":"https://community.spiceworks.com/u/brian-duffy"}},{"@type":"Answer","text":"To get the exact same result as with wmic<\/em> you have to use ExpandProperty as well<\/p>\nGet-WMIObject -Class Win32_Bios | Select-Object -ExpandProperty SerialNumber\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2014-10-15T11:30:34.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/7","author":{"@type":"Person","name":"jakubjare","url":"https://community.spiceworks.com/u/jakubjare"}},{"@type":"Answer","text":"Just to be thorough, you can also:<\/p>\n
(Get-WMIObject -Class Win32_Bios).SerialNumber\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2014-10-15T13:10:31.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/8","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"But you gotta be careful with the syntax Martin shown because that does not work in PowerShell 2 if Get-WMIObject returns more than one<\/em> object. Which in this case it does not. But<\/strong> If you queried for local users and their names, for example, you’d likely get a collection of objects.<\/p>\n(gwmi win32_userAccount ).Name\n<\/code><\/pre>\nWith PowerShell 3 this works perfectly fine and returns the names of the users. With PowerShell 2 it returns nothing.<\/p>\n
The reason for this is PowerShell 2 you query the Name of the collection itself, not each item (user) in the collection. In PowerShell 3 the engine automatically expands the collection if needed and returns Name of each disk.<\/p>\n
(Call me a dinosaur but most of the scripts I write are and have to be Posh 2 compatible )<\/p>","upvoteCount":0,"datePublished":"2014-10-15T15:19:38.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/9","author":{"@type":"Person","name":"jakubjare","url":"https://community.spiceworks.com/u/jakubjare"}},{"@type":"Answer","text":"\n\n
<\/div>\n
nohwnd:<\/div>\n
\n(Call me a dinosaur but most of the scripts I write are and have to be Posh 2 compatible )<\/p>\n<\/blockquote>\n<\/aside>\n
Isn’t that the truth? I’ve been writing all 3.0+ higher scripts even though most of our servers don’t support it just to FORCE the issue We now have “batch job” servers that are all PS 4.0.<\/p>","upvoteCount":0,"datePublished":"2014-10-15T15:26:26.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/10","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
Obviously you do not have a ton of Vista stations to support, where updating to PowerShell 3 does not make enough economical sense <\/p>","upvoteCount":0,"datePublished":"2014-10-15T15:37:00.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/11","author":{"@type":"Person","name":"jakubjare","url":"https://community.spiceworks.com/u/jakubjare"}},{"@type":"Answer","text":"\n\n
<\/div>\n
nohwnd:<\/div>\n
\nObviously you do not have a ton of Vista stations to support, where updating to PowerShell 3 does not make enough economical sense <\/p>\n<\/blockquote>\n<\/aside>\n
No, just over 500 Windows 2008 R2 servers! All the workstations are Windows 7 so if I have to write something for them I have to suffer with PS 2.0.<\/p>\n
Vista? Really?<\/p>","upvoteCount":0,"datePublished":"2014-10-15T15:48:19.000Z","url":"https://community.spiceworks.com/t/not-sure-how-to-explain/347566/12","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}}]}}
What I’m trying to do is a wmi query for the serial number that only returns the serial number. Using wmic it would look like this;
wmic bios get serialnumber
It would return this;
AJRYTS1
In PS this is what I use;
get-wmiobject -class win32_bios -property serialnumber
This is what is returned;
__GENUS : 2
__CLASS : Win32_BIOS
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
SerialNumber : AJRYTS1
PSComputerName :
How can I filter that to just give the serial number as in example one?
6 Spice ups
try:
get-wmiobject -class win32_bios -property serialnumber |fl Serialnumber
2 Spice ups
Format-list. Excellent. You da man. THX
I wish they would put an alias for the class. EG… “32_” or “64_” Maybe something along those lines…
Thanks for the super fast response Gary.
Got a, probably not for you, more complicated one. Multiple queries. Would you like it in a new thread?
I would recommend using Select-Object vs Format-Table as it keeps objects in the pipeline as objects vs formatting into a table which is only good for displaying in console
Get-WMIObject Win32_Bios | Select SerialNumber
3 Spice ups
jakubjare
(nohwnd)
October 15, 2014, 11:30am
7
To get the exact same result as with wmic you have to use ExpandProperty as well
Get-WMIObject -Class Win32_Bios | Select-Object -ExpandProperty SerialNumber
1 Spice up
martin9700
(Martin9700)
October 15, 2014, 1:10pm
8
Just to be thorough, you can also:
(Get-WMIObject -Class Win32_Bios).SerialNumber
2 Spice ups
jakubjare
(nohwnd)
October 15, 2014, 3:19pm
9
But you gotta be careful with the syntax Martin shown because that does not work in PowerShell 2 if Get-WMIObject returns more than one object. Which in this case it does not. But If you queried for local users and their names, for example, you’d likely get a collection of objects.
(gwmi win32_userAccount ).Name
With PowerShell 3 this works perfectly fine and returns the names of the users. With PowerShell 2 it returns nothing.
The reason for this is PowerShell 2 you query the Name of the collection itself, not each item (user) in the collection. In PowerShell 3 the engine automatically expands the collection if needed and returns Name of each disk.
(Call me a dinosaur but most of the scripts I write are and have to be Posh 2 compatible )
martin9700
(Martin9700)
October 15, 2014, 3:26pm
10
Isn’t that the truth? I’ve been writing all 3.0+ higher scripts even though most of our servers don’t support it just to FORCE the issue We now have “batch job” servers that are all PS 4.0.
jakubjare
(nohwnd)
October 15, 2014, 3:37pm
11
Obviously you do not have a ton of Vista stations to support, where updating to PowerShell 3 does not make enough economical sense
martin9700
(Martin9700)
October 15, 2014, 3:48pm
12
No, just over 500 Windows 2008 R2 servers! All the workstations are Windows 7 so if I have to write something for them I have to suffer with PS 2.0.
Vista? Really?