|
|
1st PS scriopt
Hello All,
I am new to Powershell (scripting in fact) and am having problems with my
first script. I am trying to query a list of servers and pull information
and export it to an Excel Spreadsheet. Powershell error:
Exception getting "Item": "Invalid index. (Exception from HRESULT:
0x8002000B (DISP_E_BADINDEX))"
At C:\gt\bios.ps1:4 char:35
+ $sheet = $workbook.worksheets.Item <<<< ("Bios Data")
+ CategoryInfo : NotSpecified: (:) [],
GetValueInvocationException
+ FullyQualifiedErrorId :
CatchFromBaseAdapterParameterizedPropertyGetValueTI
==============================================
Script:
# Varibles
$excel = New-object -comobject Excel.Application
$workbook = $excel.workbooks.add()
$sheet = $workbook.worksheets.Item("Bios Data")
$bios = systeminfo | find /i "bios version"
$Host = systeminfo | find /i "Host Name"
$x = 2
###########
$excel
$workbook
$sheet
$sheet.cells.item(1,1) = "Server Name"
$sheet.cells.item(1,2) = "Bios Date"
$workbook.worksheet.item(1).Name = "Server data"
#Get Bios Data
ForEach ($S in Get-Content(“c:\servers.txt”)) { $bios }
{
$sheet.cells.item($x, 1) = $host
$sheet.cells.item($x, 2) = $bios
$x++
}
Any help would be greatly appreciated. Thanks
--
Look at the pricetag, where they do that at?
|
|
0
|
|
|
|
Reply
|
Utf
|
12/2/2009 8:02:01 PM |
|
The cause of the error is that you're referencing a nonexistant sheet. Try
the code below, it gets the fist sheet and then renames it. Also note that
the BIOS information is obtained through Get-WMIObject, this information
needs to be concatenated to match that returned by systeminfo.exe, still,
Get-WMIObject is faster:
$excel = New-object -comobject Excel.Application
$excel.Visible = $true
$excel.DisplayAlerts = $false
$workbook = $excel.Workbooks.Add()
# get fist sheet
$sheet = $workbook.Worksheets.Item(1)
# rename first sheet
$sheet.Name = 'Bios Data'
$sheet.cells.item(1,1) = "Server Name"
$sheet.cells.item(1,2) = "Bios Data"
$x = 2
ForEach ($S in Get-Content C:\servers.txt ) {
$bios = gwmi Win32_BIOS -ComputerName $S
$biosDate = $bios.ReleaseDate -replace '^(....)(..)(..).+$', '$2/$3/$1'
$strBios = $bios.Manufacturer + ' ' + $bios.SMBIOSBIOSVersion +
', ' + $biosDate
$sheet.cells.item($x, 1) = $bios.__SERVER
$sheet.cells.item($x, 2) = $strBios
$x++
}
# adjust width of columns
[void]$sheet.UsedRange.Columns.AutoFit()
# save workbook
$workbook.SaveAs('C:\Bios Data.xlsx')
$workbook.Close()
$excel.Quit()
--
Robert
|
|
0
|
|
|
|
Reply
|
Utf
|
12/3/2009 4:34:02 AM
|
|
|
1 Replies
411 Views
(page loaded in 0.021 seconds)
Similiar Articles: 1st PS scriopt - microsoft.public.windows.powershellHello All, I am new to Powershell (scripting in fact) and am having problems with my first script. I am trying to query a list of servers and pu... Execute powershell script at startup - microsoft.public.windows ...1st PS scriopt - microsoft.public.windows.powershell Execute powershell script at startup - microsoft.public.windows ... Can my host interrupt a Powershell script ... Pause a running script - microsoft.public.windows.powershell ...Can my host interrupt a Powershell script? - microsoft.public ... 1st PS scriopt ... Script and Then Resume It When a User Presses a Key on the Keyboard? ... the first ... PowerShell and Excel - microsoft.public.windows.powershell ...1st PS scriopt - microsoft.public.windows.powershell I am trying to query a list of servers and pull information and export it to an Excel Spreadsheet. Is there a way to disconnect a session and then resume it ...1st PS scriopt - microsoft.public.windows.powershell... windows.powershell Is there a ps script which ... this topic appear first, remove this ... How to set-executionpolicy from script ? - microsoft.public ...Issue by running PS scripts from IIS7 - microsoft.public.windows ... Read ... How to create text files with the PowerShell extension .ps1. The first task is to allow script ... Remove-Windowsfeature powershell script in R2 - microsoft.public ...Right now, the first time I hit a feature/role that needs a restart, everything else ... work at once, then reboot instead > of > having to keep re-running the script ... Can't pass arguments to scripts - microsoft.public.windows ...Hello, I just upgraded to Windows 7 with PS 2.0. I have a lot of scripts that worked properly ... Is there a way to pass parameters/variables ... Writing Your First LINQ ... Invoke PowerShell Script from Batch File - microsoft.public ...How can I get the first one to work? Fred ... It works if I run it from a > PS prompt ... We'd recommend that you first head over to the Script Center, get ... Get-Service and Status - microsoft.public.windows.powershell ...Hi, I fi I run: $B = Get-Service -DisplayName "Opsware Agent" -ComputerName testserver And then $B, I get this: PS Scripts:\> $B Status... 1st PS scriopt - microsoft.public.windows.powershell | Microsoft ...Hello All, I am new to Powershell (scripting in fact) and am having problems with my first script. I am trying to query a list of servers and pu... Postscript - Wikipedia, the free encyclopediaA postscript, abbreviated PS or P.S., is writing added after the main body of a ... not usually called a postscript, is written in response to critical remarks on the first ... First line of all of my PS scripts fails ...Registered User Joined: 29 Oct 2010 Posts: 3 Quote Reply Topic: First line of all of my PS scripts fails ... Posted: 29 Oct 2010 at 3:42am My first attempt at a useful PS Script - Powershell.com ...Am trying to write my first script to solve a real need and my lack of experience with PS is showing. Any help would be appreciated..... Need to write a routine to do ... Powershell syntax - How to Run a script - SS64Run a PowerShell script. There are two ways to run a PowerShell script. Before running any scripts on a new powershell installation, you must first set an appropriate ... 7/17/2012 2:31:16 PM
|
|
|
|
|
|
|
|
|