Read path with special characters

I am writing a script that will recall archived files by reading them but it appears that I cannot read paths or documents that contain a special character in them such as a word doc containing square brackets or en-dashes in its title.

I'm using robocopy as part of my script to bypass the windows 260 path length limitation. Perhaps I could print the path out into a txt file and read from that?

My script is included below:

Function Get-FolderItem {

    Param (
        [string[]]$Path = $PWD,
        [string[]]$Filter = '*.*',    
    Begin {
        $params = New-Object System.Collections.Arraylist
        If ($PSBoundParameters['MaxAge']) {
            $params.Add("/MaxAge:$MaxAge") | Out-Null
        If ($PSBoundParameters['MinAge']) {
            $params.Add("/MinAge:$MinAge") | Out-Null
    Process {
        ForEach ($item in $Path) {
            Try {
                $item = (Resolve-Path -LiteralPath $item -ErrorAction Stop).ProviderPath
                If (-Not (Test-Path -LiteralPath $item -Type Container -ErrorAction Stop)) {
                    Write-Warning ("{0} is not a directory and will be skipped" -f $item)
                If ($PSBoundParameters['ExcludeFile']) {
                    $Script = "robocopy `"$item`" NULL $Filter $params /XF $($ExcludeFile  -join ',')"
                } Else {
                    $Script = "robocopy `"$item`" NULL $Filter $params"
                Write-Verbose ("Scanning {0}" -f $item)
                Invoke-Expression $Script | ForEach {
                    Try {
                        If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
                           $object = New-Object PSObject -Property @{
                                FullName = $matches.FullName
                            Write-Output $object
                            Get-Content $object.FullName -TotalCount 1 -Encoding Byte
                        } Else {
                            Write-Verbose ("Not matched: {0}" -f $_)
                    } Catch {
                        Write-Warning ("{0}" -f $_.Exception.Message)
            } Catch {
                Write-Warning ("{0}" -f $_.Exception.Message)

$1 = "\\nas\c$\fs_D0\Project_2004"

Get-FolderItem -Path $1
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you tried the -LiteralPath parameter for Get-Content?  I'm assuming this is where you're running into a problem.
Get-Content -LiteralPath $object.FullName -TotalCount 1 -Encoding Byte

Open in new window

If that doesn't work, please provide the error message you're getting.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vh112233Author Commented:
Hi Footech,

It worked! Thank you for the suggestion.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.