tp447
1
Hi,
I can get the Hostname, Serial and Mac from the following, but wondered if there is a better way to structure the PS?
Get-ComputerInfo | Select-Object -Property BiosSeralNumber,CSDnsHostName,{Get-NetAdapter -Name Ethernet | Select MacAddress}
Regards
Tony
Olaf
2
Maybe not a better structure but a probably slightly faster way as Get-ComputerInfo used to be very slow:
[PSCustomObject]@{
BiosSerialNumber = (Get-CimInstance -ClassName Win32_BIOS).SerialNumber
CsDNSHostName = $ENV:COMPUTERNAME
MacAddress = Get-NetAdapter -Name Ethernet | Select-Object -ExpandProperty MacAddress
}
To learn best practices and styles you could read up The Unofficial PowerShell Best Practices and Style Guide.
BTW: When you post code please format this as code using the code tag button named “PRE”. Thanks.
tp447
3
Thanks Olaf, that works nicely and the output is certainly more attractive than my code.
I will start reading through the guide, cheers for helping out here.