Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell and Excel - Can't minimize excel

$
0
0

I have a powershell script that pulls some basic information from servers and dumps it to an excel sheet.  It works fine as long as I leave the excel window open.  If I minimize the window I get blanks in my worksheet.  Any idea how I can still get the results to populate even if I minimize the window?

$erroractionpreference = "SilentlyContinue"

$a = New-Object -comobject Excel.Application
$a.visible = $true

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1)  = "Server Name"
$c.Cells.Item(1,2)  = "RAM(GB)"
$c.Cells.Item(1,3)  = "Model"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = gc $env:userprofile\desktop\list.txt
$colComputers = $colComputers.Split(",")

foreach ($strComputer in $colComputers){

$comp = gwmi Win32_computersystem -computername $strComputer

$c.Cells.Item($intRow,1)  = $comp.name
$c.Cells.Item($intRow,2)  = "{0:N0}" -f ($comp.TotalPhysicalMemory/1GB)
$c.Cells.Item($intRow,3)  = $comp.Model
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>