Hello Community
I'm a Little bit stuck with this and now I hope to find an anwser here. So any suggestions or tipps would be great. A short description of what I want to achieve.
First im declaring an Array for my final object with is called UserConfiguration
Userconfiguration = @()
Then I read an Excel file cell by cell using a given range. After that I store each line of data into a hashtable witch then will be "converted" to an pscustom object.
$ExcelApp = Get-StartApps Excel
if($ExcelApp) { $Excel = New-Object -ComObject "Excel.Application" }
else { Write-Error "No Excel App is installed on this system." -Category "Missing App" -RecommendedAction "Install a local copy of excel" -ErrorAction Stop }
$File = "AccountInfoblatt.xlsx"
$Excel.Visible = $false
$WorkBook = $Excel.Workbooks.Open($File)
$WorkSheet = $WorkBook.Sheets.Item("Eintritt")
# creating excel sheet configuration
$MaxUsedRows = ($WorkSheet.usedrange.rows).count
$MaxUsedColumns = (($WorkSheet.UsedRange.columns).count) - 1
$CurrentRow = 2
$CurrentColumn = 2
$UserConfiguration = @()
do
{
Write-Progress -Activity "Parsing User Data" -PercentComplete ($MaxUsedRows / 100 * $CurrentRow)
# Reading excel file row by row
$Data = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn + 1).Value()
$Header = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn).Value()
$Attribute = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn + 2).Value()
$UserProperties = @{
Value = $Data
Header = $Header
Attribute = $Attribute
}
$CurrentRow ++
# creating customobject
if($data -eq $null) { <# no object #> } else { $UserConfiguration += [PsCustomObject]$UserProperties }
}
while ($CurrentRow -le $MaxUsedRows)
Write-Output $UserConfiguration
So this works great for me and I'm getting an object returned with a type of System.Management.Automation.PSCustomObject
Now I want to insert a custom typename for that object so I can do a Little bit more on de Default formatting of the ouput.
If I do $userConfiguration.pstypenames on that object it tells me the following
System.Object[]
System.Array
System.Object
If I now do $userConfiguration.pstypenames.clear() it does clear all the type names. So far so good
Now I do $userConfiguration.typenames.insert(0,'My.Custom.Type'). It does this as I check the pstypenames again but now if i do a get member on the object again it still tells me that the typename is System.Management.Automation.PSCustomObject.
How can i achive this? Is this because i have an underlaying Array in this object?
Thanks for help. Cheers Lumu