Hey Powershell people. I'm running into an array issue in powershell where the error "Copy-Item : The specified path, file name, or both are too long" is thrown back at me. However, the odd thing is if I type the copy path in manually the script it works fine, so the error only occurs when the script directly references the item in the array by its numbered location. Eventually, I want to create a for loop for this that will reference each file name in the array, so i'm hoping I can directly reference the array pointer.
$DTS = get-date -format "dd-MM-yyy_hh-mm-ss"
New-Item c:\$DTS -type directory
$get = Get-Content C:\array.txt
Start-Sleep -s 1
$testdata=@"
$get
"@
($testdata | Select-String -Pattern '(?<=t.s.\\.).+?(?=\. u s p)' -AllMatches).Matches | %{$_.Value} | Out-File c:\test.txt
Start-Sleep -s 1
$get2 = Get-Content C:\test.txt
$get2 = $get2 -replace " ", "" | Out-File c:\test.txt
$get = Get-Content C:\test.txt
Copy-Item "\\server\C$\Program Files\Projects\$get[0].usp" \\server2\C$\$DTS
Note, if I do something like $get4 = $get[0] the script will properly reference $get[0] if $get4 is inserted into the copy path .