Reputation: 151
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.
Upvotes: 1
Views: 3590
Reputation: 46700
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.
Upvotes: 1
Reputation: 10019
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.
Upvotes: 2