locked
Custom object propertie stays empty RRS feed

  • Question

  • I'm trying to combine multiple values into one custom object. This is the part that is giving me trouble. I cant get de object propertie ''FullName' filled. But the value i'm tring to put in is correct. I'm missing something but can figure out what it is.


    $StartPath = "d:\"
    $TotalDepth = "2"
    $DirCounter= 1


    while($TotalDepth -gt $DirCounter){
                                        
                                        $FullPathName = @()
                                        
                                        $FullPathName += Get-ChildItem  -Path "$StartPath" -Directory | Select Name, FullName

                                        foreach($line in $FullPathName)
                                        {
                                        $acceslist = get-acl $line.FullName | select AccessToString
                                        $props =  @{'Depth'="$DirCounter";
                                                    'FullName'=$line.FullName;

                                        $obj = New-Object -TypeName PSObject -Property $props}
                                        Write-host "line.FullName:" $line.FullName; #filled
                                        Write-Host "obj.FullName :" $obj.FullName; #empty
                                        }
                                        $DirCounter = $DirCounter + "1"
                                        }

                                        
                                     





                                                                                                                                                  
    Thursday, November 16, 2017 12:34 PM

Answers

  • Believe this portion

    $props =  @{'Depth'="$DirCounter";
                                                    'FullName'=$line.FullName;
    
                                        $obj = New-Object -TypeName PSObject -Property $props}

    Should be

    $props =  @{'Depth'="$DirCounter"                                            
                'FullName'=$line.FullName}
    
    $obj = New-Object -TypeName PSObject -Property $props


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • Marked as answer by Steve-NL Thursday, November 16, 2017 12:54 PM
    Thursday, November 16, 2017 12:49 PM

All replies

  • Believe this portion

    $props =  @{'Depth'="$DirCounter";
                                                    'FullName'=$line.FullName;
    
                                        $obj = New-Object -TypeName PSObject -Property $props}

    Should be

    $props =  @{'Depth'="$DirCounter"                                            
                'FullName'=$line.FullName}
    
    $obj = New-Object -TypeName PSObject -Property $props


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • Marked as answer by Steve-NL Thursday, November 16, 2017 12:54 PM
    Thursday, November 16, 2017 12:49 PM
  • You make it look so easy. It works like a charm now. Thanks Clayman2
    Thursday, November 16, 2017 12:54 PM