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

Powershell PSObjects does not save data in excel sheet.

$
0
0

Hi,

I am trying to save Powershell script with PSObjects to capture Registry data which is not able to save in excel sheet.

Earlier i have captured registry data using Microsoft.Win32.RegistryKey, & was able to capture it in excel sheet, but not with PSObjects this time.

Here is my code:

$date = Get-Date
$ComputerName = "localhost"
$a = New-Object -comobject Excel.Application
$a.visible = $True

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

$c.Cells.Item(1,1) = "Type"
$c.Cells.Item(1,2) = "Name"
$c.Cells.Item(1,3) = "PathFind"
$c.Cells.Item(1,4) = "Value"

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

function Get-InstalledAppReg ([string]$ComputerName)
{
$Path3 = "HKLM:\SOFTWARE\Microsoft\Internet Explorer"

$Keys = get-ChildItem -path $path3 -recurse
forEach($Key in $Keys)
{
    $i = 2
    forEach ($Value in $Key.GetValueNames())
    {
        New-Object PSObject -Property @{
       
        $c.Cells.Item($i,1) = $Key.GetValueKind($Value)
        $c.Cells.Item($i,2) = $Value
        $c.Cells.Item($i,3) = $Key.Name
        $c.Cells.Item($i,4) = $Key.GetValue($Value)
       
       
       
        }
        $i ++
    }
   
}

}
Get-InstalledAppReg ([string]$ComputerName)
$d.EntireColumn.AutoFit()
$a.Application.Displayalerts = $false


$b.SaveAs("c:\$date.xlsx")

 

here the script runs showing up the data in console, but does not save in excel sheet.

Any help is appreciated.

I am reachable at getarindam@gmail.com

 

Thanks

Arindam


Viewing all articles
Browse latest Browse all 6937

Trending Articles