ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell - The path is not of a legal form

    IT Discussion
    powershell errors
    3
    9
    2.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DustinB3403D
      DustinB3403
      last edited by

      So in my on-going project to rid our files of special characters I got a new error, specifically The path is not of a legal form. Anyone have any ideas on what this actually means?

      In looking at $error[0] it just repeats the limited error message and doesn't specify where the error issue (or what file or folder) is messed up.

      1 Reply Last reply Reply Quote 0
      • DustinB3403D
        DustinB3403
        last edited by

        In getting the verbose logging I have this

        System.
        Management.Automation.CmdletProviderInvocationException: The path is not of a legal form. ---> System.ArgumentException: The path is not of a legal form.
           at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
           at System.IO.Path.InternalGetDirectoryName(String path)
           at Microsoft.PowerShell.Commands.FileSystemProvider.RenameItem(String path, String newName)
           at System.Management.Automation.SessionStateInternal.RenameItem(CmdletProvider providerInstance, String path, String newName, CmdletProviderContext context)
           --- End of inner exception stack trace ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
           at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAst
        s, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
           at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)]
        

        Still not super helpful, unless it's saying that a file path is too long - but which one?

        1 Reply Last reply Reply Quote 0
        • M
          manxam
          last edited by

          Hey Dustin, you may already have this code in place somewhere, but what about piping the currently worked on file/path via Write-Debug so that it shows this info or, at the least, the file directly prior to it?

          Also, assuming you're removing special characters and not replacing them with something else, is it possible that there is a file that contains entirely these characters and when they're removed there is no file name?

          DustinB3403D 1 Reply Last reply Reply Quote 2
          • DustinB3403D
            DustinB3403 @manxam
            last edited by

            @manxam said in Powershell - The path is not of a legal form:

            Hey Dustin, you may already have this code in place somewhere, but what about piping the currently worked on file/path via Write-Debug so that it shows this info or, at the least, the file directly prior to it?

            Well I could probably do this, I'd rather not as everything would get dumped to the console as this is running. Which would create scroll-hell.

            @manxam said in Powershell - The path is not of a legal form:

            Also, assuming you're removing special characters and not replacing them with something else, is it possible that there is a file that contains entirely these characters and when they're removed there is no file name?

            The likelihood of this is very very small, but yes I am replacing all stupid special characters with a null space (delete essentially), so while possible not in an practical sense that would ever occur.

            JaredBuschJ 1 Reply Last reply Reply Quote 0
            • JaredBuschJ
              JaredBusch @DustinB3403
              last edited by

              @DustinB3403 said in Powershell - The path is not of a legal form:

              Well I could probably do this, I'd rather not as everything would get dumped to the console as this is running. Which would create scroll-hell.

              That is the point of debugging.. once you have worked it out, then you remove it.

              DustinB3403D 1 Reply Last reply Reply Quote 0
              • DustinB3403D
                DustinB3403 @JaredBusch
                last edited by

                @JaredBusch said in Powershell - The path is not of a legal form:

                @DustinB3403 said in Powershell - The path is not of a legal form:

                Well I could probably do this, I'd rather not as everything would get dumped to the console as this is running. Which would create scroll-hell.

                That is the point of debugging.. once you have worked it out, then you remove it.

                As always your words ring true.

                M 1 Reply Last reply Reply Quote 0
                • M
                  manxam @DustinB3403
                  last edited by

                  @DustinB3403 : That's the reason I suggested Write-Debug (or Write-Verbose) so that this would not show up on the console by default.

                  DustinB3403D 1 Reply Last reply Reply Quote 1
                  • DustinB3403D
                    DustinB3403 @manxam
                    last edited by

                    @manxam said in Powershell - The path is not of a legal form:

                    @DustinB3403 : That's the reason I suggested Write-Debug (or Write-Verbose) so that this would not show up on the console by default.

                    I'll give write-verbose -message "my msg" -verbose a go and see what happens.

                    1 Reply Last reply Reply Quote 0
                    • DustinB3403D
                      DustinB3403
                      last edited by

                      I think I may have found a quicker/more clean means of doing this with just

                      Get-ChildItem -Path "Drive-Letter" -Recurse -Force

                      It prints everything out to the console or to a file for review, than you just have to read it.

                      1 Reply Last reply Reply Quote 1
                      • 1 / 1
                      • First post
                        Last post