Create New-Object(s) named from names in a pipe

Viewed 82

Hello Stackoverflow powershell experts

I just started out on this website and so hope to earn some kudos answering questions as well as only asking questions that can contribute to this awesome knowledge base that is the Stackoverflow community.

My Powershell skills are growing each day however i am having difficulty understanding why this is not working as demonstrated.

I want to create a bunch of new objects named from a list of names kept in a noteproperty of a pscustomobject

    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> $ADSObjectNames

    ObjectName                     CSV                                            
    ----------                     ---                                            
    Process                        580501780015_Process.csv                       
    Applications                   580501780015_Applications.csv                  
    ApplicationResourceAssociation 580501780015_ApplicationResourceAssociation.csv
    NetworkInterface               580501780015_NetworkInterface.csv              
    SystemPerformance              580501780015_SystemPerformance.csv             
    Tags                           580501780015_Tags.csv                          
    Connection                     580501780015_Connection.csv                    
    Server                         580501780015_Server.csv                        



    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> $ADSObjectNames | Select-Object -Property ObjectName | ForEach-Object {$_.objectname = New-Object -TypeName pscustomobject}


    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> Get-Variable | Where-Object {$_.Name -eq 'Process'}

    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> Get-Variable | Where-Object {$_.Name -eq 'Server'}

    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner>

$ADSObjectNames breakdown is as follows:

    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> $ADSObjectNames | gm


       TypeName: System.Management.Automation.PSCustomObject

    Name        MemberType   Definition                         
    ----        ----------   ----------                         
    Equals      Method       bool Equals(System.Object obj)     
    GetHashCode Method       int GetHashCode()                  
    GetType     Method       type GetType()                     
    ToString    Method       string ToString()                  
    CSV         NoteProperty string CSV=580501780015_Process.csv
    ObjectName  NoteProperty string ObjectName=Process          



    PS G:\Team Drives\Projects\AWS-PowerShell\AWS_ADS_DataMiner> 

Any insight from your experience and knowledge would be greatly appreciated.

Thanks Stackoverflow'peops

Stuart

1 Answers
Related