Save xml file containing square bracket and dashes

Welcome Forums General PowerShell Q&A Save xml file containing square bracket and dashes

Viewing 3 reply threads
  • Author
    Posts
    • #195827
      Participant
      Topics: 4
      Replies: 9
      Points: 30
      Rank: Member

      I have xl file which i modify but when I try to save it, i get access denied error.

      $file = "C:\Temp\[Name] Test [Name2] – Name3 = Name4.nfo"

      [xml]$data = Get-Content -LiteralPath $file

      $data.xml.title = "New name"

      $data.Save($file);

       

      Exception calling "Save" with "1" argument(s): "Access to the path 'C:\Temp\[Name] Test [Name2] – Name3 = Name4.nfo' is denied."
      At line:6 char:1
      + $data.Save($file);
      + ~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodException

       

    • #195842
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      The error is Access Denied. Can you save to another file path? Is that file in use by an application?

    • #195908
      Participant
      Topics: 4
      Replies: 9
      Points: 30
      Rank: Member

      If the file is hidden it doesnt work but if the file is not hidden it worked fine. All ok now

    • #195938
      js
      Participant
      Topics: 27
      Replies: 739
      Points: 2,013
      Helping Hand
      Rank: Community Hero

      Must you use the square brackets in the name? Those are powershell wildcards.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.