Page 1 of 1

How to correctly add credentials

Posted: Thu Dec 02, 2010 9:59 am
by mrshortcut

I am trying to gather the bios levels (and anything else I can) for some workstations. I found the following script below that was told would gather the requested information, but I cannot figure out where I need to add the " -credential (my credentials)" to avoid the access error. Can anyone please assist?

Code: Select all

	

	
	
$strComputer = Get-Content -Path "C:bios.txt"
	$colItems = get-wmiobject -class "Win32_BIOS" -namespace "rootCIMV2" `
-computername $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
} 

How to correctly add credentials

Posted: Thu Dec 02, 2010 10:45 am
by jvierra
type: help get-wmiobject -full

Look at the examples of using credentials.


How to correctly add credentials

Posted: Thu Dec 02, 2010 1:38 pm
by jvierra
One small step at a tme.

Look at the examples:
Help Get-Credential -full

Useful commands:

help commands
help help
Help *someword* ( example: help *item*)



How to correctly add credentials

Posted: Thu Dec 02, 2010 2:23 pm
by mrshortcut
help export-csv -full

You cannot concatenate CSV files.

You can collect all data into a collection before outputting.

Code: Select all

get-wmiobject Win32_BIOS -computer (cat servers.txt) -credential $creds |
Export-Csv file.csv

The above will create a file of all servers in one CSV.



I tried running that for one computer substituting the IP for (cat servers.txt) and the credention for $creds and the CSV resulted in only the following


#TYPE System.String

Length

1



I now have the following which runs fine within the powershell window, but I cant get the export to CSV correct. I understand it has to go after all the data is collected but I still don't understand which part of the script it goes to because of the substrings.

I read through the examples but since this appears more complex I cant put 2 and 2 together. I assume it would go at the end of the $colItems since that is the line with the get-wmiobject, but it errors out when I do so

Code: Select all

$cred = Get-Credential
$arrComputers = get-Content -Path "C:bios.txt"
foreach ($strComputer in $arrComputers)
{
$colItems = get-wmiobject -credential $cred -class "Win32_BIOS" -namespace "rootCIMV2" `
-computername $strComputer
foreach ($objItem in $colItems)
{
Write-host "Computer Name: " $strComputer
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
}