none
importing file paths via csv failing - the data is produced if I manually feed the variable the pathway

    Question

  • hi awesome team of greatness.  looking to understand why I have this issue rather than just fixing the problem.  I have a script that works for getting the folder structure of a given pathway to 3 levels, i can call the various information I want no problem. 
    #this gets the drive structure for a list of drive paths
    $pathlist = "\\internal\dfs\folder\targetfolder"
    
    foreach ($path in $pathlist) {
                                                             Get-ChildItem $path\*, $path\*\*, $path\*\*\* -Directory  | select name,pspath,PSChildName,basename,parent,root,extension | export-csv c:\temp\MapDrives.csv -force -Append -NoTypeInformation
            
    }
    
    
    however when i try and list (in this instance 8) the paths in a csv file, it calls the get-object on the pc c drive pathway rather than the DFS share. I've tried to look through this site (feel free to point me to a previously supplied answer), and gone through by nuggets again, coming up against a wall with this one. help would be appreciated.
    Monday, November 11, 2013 4:00 AM

Answers

  • Hi,

    this indicates that the value of the $path variable is $null.

    How do you import the path names, how does your .csv file look like?

    If you have a .csv file with Paths that are in a column called "Path" you can do it like below:

    $pathlist = Import-Csv myCSV.csv | select -ExpandProperty Path
    
    foreach ($path in $pathlist) {
        Get-ChildItem $path\*, $path\*\*, $path\*\*\* -Directory  | 
            select name,pspath,PSChildName,basename,parent,root,extension | 
            export-csv c:\temp\MapDrives.csv -force -Append -NoTypeInformation
    }
    

    • Marked as answer by vinneth Tuesday, November 12, 2013 3:50 AM
    Monday, November 11, 2013 1:57 PM

All replies

  • Hi,

    this indicates that the value of the $path variable is $null.

    How do you import the path names, how does your .csv file look like?

    If you have a .csv file with Paths that are in a column called "Path" you can do it like below:

    $pathlist = Import-Csv myCSV.csv | select -ExpandProperty Path
    
    foreach ($path in $pathlist) {
        Get-ChildItem $path\*, $path\*\*, $path\*\*\* -Directory  | 
            select name,pspath,PSChildName,basename,parent,root,extension | 
            export-csv c:\temp\MapDrives.csv -force -Append -NoTypeInformation
    }
    

    • Marked as answer by vinneth Tuesday, November 12, 2013 3:50 AM
    Monday, November 11, 2013 1:57 PM
  • thanks Dirk, the answer is obvious as soon as i read it.  I have used -ExpandProperty many times, don't know how i missed it. 

    Tuesday, November 12, 2013 3:50 AM