How to correctly add credentials

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
mrshortcut
Posts: 7
Joined: Tue Nov 30, 2010 4:32 am

How to correctly add credentials

Post by mrshortcut » Thu Dec 02, 2010 10:59 am


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
} 

User avatar
jvierra
Posts: 13280
Joined: Tue May 22, 2007 9:57 am
Contact:

How to correctly add credentials

Post by jvierra » Thu Dec 02, 2010 11:45 am

type: help get-wmiobject -full

Look at the examples of using credentials.


User avatar
jvierra
Posts: 13280
Joined: Tue May 22, 2007 9:57 am
Contact:

How to correctly add credentials

Post by jvierra » Thu Dec 02, 2010 2:38 pm

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*)



User avatar
mrshortcut
Posts: 7
Joined: Tue Nov 30, 2010 4:32 am

How to correctly add credentials

Post by mrshortcut » Thu Dec 02, 2010 3:23 pm

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
}

Locked