web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error when trying to c...
Power Automate
Unanswered

Error when trying to create a folder with New folder name = %PowershellOutput%

(0) ShareShare
ReportReport
Posted on by 41

Dear community,

I get an error I can't fix when running my flow containing 2 lines:

  • The first runs a powershell script that at the end generate a text stored in the variable %PowershellOutput%.
  • The second, "Create Folder", with "New folder name" : %PowershellOutput%

This flow fails at the second step with the error below:

 

Correlation Id: 99df0749-7b20-4469-910f-9de256361e33

Illegal characters in path.: Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Can't create folder folder
into C:\Users\XXXXXXX\OneDrive - XXXX\Desktop. ---> System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.Flow.RPA.Desktop.Modules.Folder.Actions.FolderActions.CreateFolder(Variant newFolderPath, Variant newFolderName, Variant& newFolder)
--- End of inner exception stack trace ---
at Microsoft.Flow.RPA.Desktop.Modules.Folder.Actions.CreateFolder.Execute(ActionContext context)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)

 

I checked that %PowershellOutput% was not containing any "Illegal characters" by setting the value to a simple "NewFolder" without any result. (I checked with a Display Message that the value was correct).

 

I also tried to use an "intermediate" variable containing th %PowershellOutput% and to use it in Create Folder as "New Folder Name" but it failed to.

Any help would be very welcome.

Regards.

 

I have the same question (0)
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    This error indicates that your script output contains characters that are not allowed in a folder/file name by the Windows file system. Try using the following action (you can copy and paste this into PAD directly to create the action for you):

    Text.Replace Text: PowershellOutput TextToFind: $'''[<>:\"/\\\\|?\\*]''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> PowershellOutput

    Paste this right after your Run PowerShell script action so that the illegal characters are replaced before you try to create the folder.

    This will replace any illegal character with nothing. If you want to, you can instead pass in a whitespace by doing %" "% or an underscore or something like that.

     

    Also, the Windows file system does not like whitespaces as the first and last characters in the file/folder name. So, I would suggest using Trim text to clean it up, as well, because scripting actions might return the value with a whitespace or even a newline at the end.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Emmanuel9 Profile Picture
    41 on at

    Dear Agnus. Thank you for your feedback. Unfortunately after copy / paste in PAD the error remains the same.

    Even if the %PowershellOutput% value seems ok ie "folder" here below:

    Emmanuel9_0-1691414160336.png

    A real headache!

     

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Can you share some screenshots of your flow and also the parameters of the Create folder action?

  • Emmanuel9 Profile Picture
    41 on at

    Sure:

    The flow:

     

    Emmanuel9_2-1691416628009.png

    And the action:

    Emmanuel9_3-1691416675750.png

    Below the red rectangle are only numbers.

    Of course I tried to manually create the new-folder inside the target folder and it works.

     

    I also tried to replace the %PowerShellOutput% by a value, for instance "folder" that is the output of the Script, and it works perfectly.

     

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Have you tried using Trim text on %PowershellOutput% as I previously suggested?

  • Emmanuel9 Profile Picture
    41 on at

    I tried to trim inside Powershell script -> Failed.

    I then add the "trim text" action directly in PAD and it works perfectly.

    Many thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard