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.BiosCharacteristics
 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.IdentificationCode
 write-host “Installable Languages: ” $objItem.InstallableLanguages
 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.SMBIOSMajorVersion
 write-host “SMBIOS Minor Version: ” $objItem.SMBIOSMinorVersion
 write-host “SMBIOS Present: ” $objItem.SMBIOSPresent
 write-host “Software Element ID: ” $objItem.SoftwareElementID
 write-host “Software Element State: ” $objItem.SoftwareElementState
 write-host “Status: ” $objItem.Status
 write-host “Target Operating System: ” $objItem.TargetOperatingSystem
 write-host “Version: ” $objItem.Version
 write-host | Out-File c:\scripts\biosinfo.txt -width 120
 }
lipotechSys EngAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:
Hi

Use

 write-host “BIOS Characteristics: ” $objItem.BiosCharacteristics | Out-File -filepath “C:MyScriptsBIOS.txt” -append

Please see eg
http://www.powershellpro.com/powershell-tutorial-introduction/wmi-part3/
oBdACommented:
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:
$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"

Open in new window

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

Open in new window

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"

Open in new window

lipotechSys EngAuthor Commented:
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
Check Out How Miercom Evaluates Wi-Fi Security!

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom on how WatchGuard's Wi-Fi security stacks up against the competition plus a LIVE demo!

oBdACommented:
Sorry, my bad.
In line 31, "$PropertyList" should be "$PropertyListFriendly".
lipotechSys EngAuthor Commented:
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
oBdACommented:
Since that's utterly unrelated to the original question, you should open a new question for this,
Feel free to post a link here, though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lipotechSys EngAuthor Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.