1
Get-ChildItem "$Folder" *.xlsx -Recurse | ?{-not ($_.PSIsContainer -or (Test-Path "I:\TEMP_Dir_SSN\$_"))} | copy-Item -Destination "I:TEMP_Dir_SSN" | out-null

Get-ChildItem "$Folder" *.xlsx -Recurse | %{
        $test = Resolve-Path $_.FullName 
        $holdArray += $test.path

}
    $holdArray | out-file "I:\TEMP_Dir_SSN\fullPath.txt" -append

The output:

I:\1992.xlsxI:\projects\confluence\projects\documents\XXXX_ComplianceRegulations.xlsxI:\projects\confluence\projects\documents\XXXX_vendorCloudStandardsPoliciesRegs.xlsx

I want it:

I:\1992.xlsx 

I:\projects\confluence\projects\documents\XXXX_ComplianceRegulations.xlsx 

I:\projects\confluence\projects\documents\XXXX_vendorCloudStandardsPoliciesRegs.xlsx

I'm not sure what is going wrong here. It should be adding it to the next line down, not appending it to the end of the string.

2 Answers 2

2

Change $holdArray += $test.path to [array]$holdArray += $test.path

You have not told PowerShell this is an array so it is treating it as a string.

Sign up to request clarification or add additional context in comments.

3 Comments

@schnipdip Also an option. There, you are telling PowerShell to create an empty array before you fill it. Equally valid is: $holdArray = @($test.path) :-)
I like to do $holdArray = @() when I am working with for loops because then I just output into an array. It is visually easier for me to understand what is happening. So if something goes awry, I can understand where the problem lays. This was just forgetting to add that part hahahaha
why i love powershell: it is easy to make things happen.
1

You are flattening the "array" to a space delimited string since you have not declared $holdArray initially. Skip the array "build" logic and use the pipeline to get the results you want.

Get-ChildItem $Folder *.xlsx -Recurse | 
    Resolve-Path | Convert-Path | 
    Add-Content "I:\TEMP_Dir_SSN\fullPath.txt"

Add-Content appends by default.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.