PropertyAssignmentException if using Format-Table

Hey,

I try to create Excel worksheets for each running process.

$Excel = New-Object -ComObject Excel.Application

function SelectApps
{
    BEGIN {}
    PROCESS {Get-Process | Select ProcessName | Group ProcessName | Format-Table Name -Auto}
    END {}
    }
    
ForEach ($i in SelectApps)
{
    $Excel.Worksheets.Add()
    $Excel.Worksheets.Item(1).Name = "$i"
    #$i
    }

But this doesn't work and ends with the following Error.

Ausnahme beim Festlegen von "Name": "Der eingegebene Name fr ein Blatt oder Diagramm ist ungltig. Stellen Sie Folgendes sicher:

 Der eingegebene Name weist maximal 31 Zeichen auf.
 Der Name enthlt keines der folgenden Zeichen:  :  \  /  ?  *  [  oder  ]
 Es wurde ein Name eingegeben."
Bei Zeile:4 Zeichen:31
+     $Excel.Worksheets.Item(1). <<<< Name = "$i"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
What I need to do to solve this problem?

Greetings
Uemit

March 31st, 2015 6:23am

Don't use format-* if you are expecting to do more with the data. PowerShell adds its own custom formatting to the data and essentially ruins it for use with anything else other than displaying it on the console.

More info:

http://learn-powershell.net/2012/04/18/scripting-games-2012-know-when-to-use-format-table/

 
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 6:30am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics