Bobby Batts
asked on
Problem Outputting BIOS Info to A Text File
I am using the following PS Script to dump BIOS info to a text file. For some reason the is executing normally, but the output file is not being created. Do I have a problem with syntax? I am trying to output to c:\scripts\biosinfo.txt.
-------------------------- ------
$strComputer = “.”
$colItems = get-wmiobject -class Win32_BIOS -namespace root\CIMV2 -comp $strComputer
foreach ($objItem in $colItems) {
write-host “BIOS Characteristics: ” $objItem.BiosCharacteristi cs
write-host “BIOS Version: ” $objItem.BIOSVersion
write-host “Build Number: ” $objItem.BuildNumber
write-host “Caption: ” $objItem.Caption
write-host “Code Set: ” $objItem.CodeSet
write-host “Current Language: ” $objItem.CurrentLanguage
write-host “Description: ” $objItem.Description
write-host “Identification Code: ” $objItem.IdentificationCod e
write-host “Installable Languages: ” $objItem.InstallableLangua ges
write-host “Installation Date: ” $objItem.InstallDate
write-host “Language Edition: ” $objItem.LanguageEdition
write-host “List Of Languages: ” $objItem.ListOfLanguages
write-host “Manufacturer: ” $objItem.Manufacturer
write-host “Name: ” $objItem.Name
write-host “Other Target Operating System: ” $objItem.OtherTargetOS
write-host “Primary BIOS: ” $objItem.PrimaryBIOS
write-host “Release Date: ” $objItem.ReleaseDate
write-host “Serial Number: ” $objItem.SerialNumber
write-host “SMBIOS BIOS Version: ” $objItem.SMBIOSBIOSVersion
write-host “SMBIOS Major Version: ” $objItem.SMBIOSMajorVersio n
write-host “SMBIOS Minor Version: ” $objItem.SMBIOSMinorVersio n
write-host “SMBIOS Present: ” $objItem.SMBIOSPresent
write-host “Software Element ID: ” $objItem.SoftwareElementID
write-host “Software Element State: ” $objItem.SoftwareElementSt ate
write-host “Status: ” $objItem.Status
write-host “Target Operating System: ” $objItem.TargetOperatingSy stem
write-host “Version: ” $objItem.Version
write-host | Out-File c:\scripts\biosinfo.txt -width 120
}
--------------------------
$strComputer = “.”
$colItems = get-wmiobject -class Win32_BIOS -namespace root\CIMV2 -comp $strComputer
foreach ($objItem in $colItems) {
write-host “BIOS Characteristics: ” $objItem.BiosCharacteristi
write-host “BIOS Version: ” $objItem.BIOSVersion
write-host “Build Number: ” $objItem.BuildNumber
write-host “Caption: ” $objItem.Caption
write-host “Code Set: ” $objItem.CodeSet
write-host “Current Language: ” $objItem.CurrentLanguage
write-host “Description: ” $objItem.Description
write-host “Identification Code: ” $objItem.IdentificationCod
write-host “Installable Languages: ” $objItem.InstallableLangua
write-host “Installation Date: ” $objItem.InstallDate
write-host “Language Edition: ” $objItem.LanguageEdition
write-host “List Of Languages: ” $objItem.ListOfLanguages
write-host “Manufacturer: ” $objItem.Manufacturer
write-host “Name: ” $objItem.Name
write-host “Other Target Operating System: ” $objItem.OtherTargetOS
write-host “Primary BIOS: ” $objItem.PrimaryBIOS
write-host “Release Date: ” $objItem.ReleaseDate
write-host “Serial Number: ” $objItem.SerialNumber
write-host “SMBIOS BIOS Version: ” $objItem.SMBIOSBIOSVersion
write-host “SMBIOS Major Version: ” $objItem.SMBIOSMajorVersio
write-host “SMBIOS Minor Version: ” $objItem.SMBIOSMinorVersio
write-host “SMBIOS Present: ” $objItem.SMBIOSPresent
write-host “Software Element ID: ” $objItem.SoftwareElementID
write-host “Software Element State: ” $objItem.SoftwareElementSt
write-host “Status: ” $objItem.Status
write-host “Target Operating System: ” $objItem.TargetOperatingSy
write-host “Version: ” $objItem.Version
write-host | Out-File c:\scripts\biosinfo.txt -width 120
}
Write-Host doesn't write output to the pipeline, so any attempt at processing its output further is doomed.
Then there's too much VB script in that script.
Simple export as formatted list:
Then there's too much VB script in that script.
Simple export as formatted list:
$PropertyList = @(
"BIOSCharacteristics",
"BIOSVersion",
"BuildNumber",
"Caption",
"CodeSet",
"CurrentLanguage",
"Description",
"IdentificationCode",
"InstallableLanguages",
"InstallDate",
"LanguageEdition",
"ListOfLanguages",
"Manufacturer",
"Name",
"OtherTargetOS",
"PrimaryBIOS",
"ReleaseDate",
"SerialNumber",
"SMBIOSBIOSVersion",
"SMBIOSMajorVersion",
"SMBIOSMinorVersion",
"SMBIOSPresent",
"SoftwareElementID",
"SoftwareElementState",
"Status",
"TargetOperatingSystem",
"Version"
)
Get-WmiObject -Class Win32_BIOS -Namespace root\CIMV2 | Format-List -Property $PropertyList | Out-String | Out-File -FilePath "C:\Scripts\biosinfo.txt"
Or to create a csv, replace the last line in the script above with this:Get-WmiObject -Class Win32_BIOS -Namespace root\CIMV2 | Select-Object -Property $PropertyList | Export-Csv -Path "C:\Scripts\biosinfo.txt" -NoTypeInformation
Or, as in your original script, with a more customized output, making use of the fact that the friendly names only differ by additional spaces from the original property names:$PropertyListFriendly = @(
"BIOS Characteristics",
"BIOS Version",
"Build Number",
"Caption",
"Code Set",
"Current Language",
"Description",
"Identification Code",
"Installable Languages",
"Install Date",
"Language Edition",
"List Of Languages",
"Manufacturer",
"Name",
"Other Target OS",
"Primary BIOS",
"Release Date",
"Serial Number",
"SMBIOS BIOS Version",
"SMBIOS Major Version",
"SMBIOS Minor Version",
"SMBIOS Present",
"Software Element ID",
"Software Element State",
"Status",
"Target Operating System",
"Version"
)
$BIOS = Get-WmiObject -Class Win32_BIOS -Namespace root\CIMV2
$PropertyList | % {
"$($_): $($BIOS.$($_.Replace(' ', '')))"
} | Out-File -FilePath "C:\Scripts\biosinfo.txt"
ASKER
oBdA,
I cut and pasted the code sample you provided into the PowerShell console. I am getting the error below on 'line 32 char:19'. How can I get around the null expression being referenced?
-------------------------
PS C:\Windows\system32> $PropertyListFriendly = @(
"BIOS Characteristics",
"BIOS Version",
"Build Number",
"Caption",
"Code Set",
"Current Language",
"Description",
"Identification Code",
"Installable Languages",
"Install Date",
"Language Edition",
"List Of Languages",
"Manufacturer",
"Name",
"Other Target OS",
"Primary BIOS",
"Release Date",
"Serial Number",
"SMBIOS BIOS Version",
"SMBIOS Major Version",
"SMBIOS Minor Version",
"SMBIOS Present",
"Software Element ID",
"Software Element State",
"Status",
"Target Operating System",
"Version"
)
$BIOS = Get-WmiObject -Class Win32_BIOS -Namespace root\CIMV2
$PropertyList | % {
"$($_): $($BIOS.$($_.Replace(' ', '')))"
} | Out-File -FilePath "C:\Scripts\biosinfo.txt"
-------------------------- ---------- --- See Error Below -------------------------- -----
You cannot call a method on a null-valued expression.
At line:32 char:19
+ $BIOS.$($_.Replace <<<< (' ', ''))
+ CategoryInfo : InvalidOperation: (Replace:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I cut and pasted the code sample you provided into the PowerShell console. I am getting the error below on 'line 32 char:19'. How can I get around the null expression being referenced?
-------------------------
PS C:\Windows\system32> $PropertyListFriendly = @(
"BIOS Characteristics",
"BIOS Version",
"Build Number",
"Caption",
"Code Set",
"Current Language",
"Description",
"Identification Code",
"Installable Languages",
"Install Date",
"Language Edition",
"List Of Languages",
"Manufacturer",
"Name",
"Other Target OS",
"Primary BIOS",
"Release Date",
"Serial Number",
"SMBIOS BIOS Version",
"SMBIOS Major Version",
"SMBIOS Minor Version",
"SMBIOS Present",
"Software Element ID",
"Software Element State",
"Status",
"Target Operating System",
"Version"
)
$BIOS = Get-WmiObject -Class Win32_BIOS -Namespace root\CIMV2
$PropertyList | % {
"$($_): $($BIOS.$($_.Replace(' ', '')))"
} | Out-File -FilePath "C:\Scripts\biosinfo.txt"
--------------------------
You cannot call a method on a null-valued expression.
At line:32 char:19
+ $BIOS.$($_.Replace <<<< (' ', ''))
+ CategoryInfo : InvalidOperation: (Replace:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Sorry, my bad.
In line 31, "$PropertyList" should be "$PropertyListFriendly".
In line 31, "$PropertyList" should be "$PropertyListFriendly".
ASKER
oBdA,
Okay, great that worked. Superior support! Excellent response time!
Now that I can read the BIOS info on each server, I need to index parent and child OUs to find accounts that do have a comma in the username. See the example username:
Doe, John verses DoeJohn
I guess I would search based on the comma ',' within each OU.
The following is an example of the organizational structure:
contoso.corp
INC
Members
Users
contoso.corp
EAST
Members
Users
.
.
.
How would I create an array to begin indexing at Contoso, then INC, then Members and finally Users.
My objective would be to search for accounts in the Users OU.
-----------
Let me know if I need to open a new question.
Lipotech
Okay, great that worked. Superior support! Excellent response time!
Now that I can read the BIOS info on each server, I need to index parent and child OUs to find accounts that do have a comma in the username. See the example username:
Doe, John verses DoeJohn
I guess I would search based on the comma ',' within each OU.
The following is an example of the organizational structure:
contoso.corp
INC
Members
Users
contoso.corp
EAST
Members
Users
.
.
.
How would I create an array to begin indexing at Contoso, then INC, then Members and finally Users.
My objective would be to search for accounts in the Users OU.
-----------
Let me know if I need to open a new question.
Lipotech
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Use
write-host “BIOS Characteristics: ” $objItem.BiosCharacteristi
Please see eg
http://www.powershellpro.com/powershell-tutorial-introduction/wmi-part3/