Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Building Excel Spreadsheet - From Inside Powershell Script

$
0
0

Greetings,

Let me preface this post by stating I am a noob to powershell.  I am still in the very beginning phases of learning.  Thus far I have been able to pull down scripts, piece them together, and compile them (after many hours).  Please keep in mind the scripts have been very entry level. 

It was suggested that I create a new topic, and link the previous post I appended my question to, so here it is: (http://powershell.com/cs/forums/t/13296.aspx). 

With that said, here is what I would like to do.  I have many scripts I have pieced together that all primarily pull data from a text file, and output that data to excel or to a text file.  I chose a simple script from the link I mentioned above, only as a reference as it appears to be a relatively simple script.  Rather then have the data outputted to an excel file at the end, I would like to learn how to achieve the same thing, however have the script launch Excel, and begin filling in the data as I watch.

Not that it matters, however, I would like to do this so I can visibly see how far along the script is coming along.  I currently have a script that does this successfully, but since I am still learning powershell, and working with variables etc.. I was hoping somebody could help me, since I haven't had much luck.

Here is the script that I took from the link I posted above, please note that I understand that the export-csv line towards the end wouldn't be needed, since we'd be building a new sheet (I believe):

------------------------------------------------------------------------------------------------------------

Get-Content .\Servers.txt | ForEach-Object {
    if(Test-Connection -ComputerName $_ -Quiet -Count 1) {
        New-Object -TypeName PSCustomObject -Property @{
            VMName = $_
            'Ping Status' = 'Ok'
        }
    } else {
        New-Object -TypeName PSCustomObject -Property @{
            VMName = $_
            'Ping Status' = 'Failed'
        }
    }
} | Export-Csv -Path Results.csv -NoTypeInformation

------------------------------------------------------------------------------------------------------------

Here is what I believe needs to happen first to launch Excel, and build out the worksheet etc.. however I don't know how to actually get the script to fill in the cells. I am not at all partial on if this is csv or excel format etc.. I can alway's pull the data out myself, or learn more about that at a later time.

------------------------------------------------------------------------------------------------------------

$excel = new-object -comobject Excel.Application
$excel.visible = $true

$workbook = $excel.workbooks.add()
$worksheet = $workbook.ActiveSheet

------------------------------------------------------------------------------------------------------------

As you can tell, I'm not really sure what I'm doing here, and would appreciate any assistance.  Again, using this script as an example, I would like to pull specific servers from a text file (already setup) and ping each of them to determine their up-time.  While this is occurring, I would like to be able to watch the data populate into the spreadsheet.

I apologize for any dumb questions, and appreciate your patience with me.  Thanks for your help, and time.


Viewing all articles
Browse latest Browse all 8583

Trending Articles