Search code examples
powershellsyntaxconcatenationmkdir

mkdir path error - Trying to concatenate strings


I am trying to just make a directory, but I cannot figure it out. I am trying to make a template so I want everything in the program to reference the form name. I am using Powershell Studio to write this program.

This does not work (Desired method):

$FormName = $formChangeMe.Text | out-string
$PATHDIR = ($env:USERPROFILE + "\AppData\Local\Tools\" + $FormName)
md -Force $PATHDIR

Output from $PATHDIR returns C:\Users\Username\AppData\Local\Tools\ChangeMe but it wont make the directory.

This does work:

$PATHDIR = "C:\Users\Username\AppData\Local\Tools\ChangeMe"
md -Force $PATHDIR

I cant see why the one works and the other doesn't. I don't think I understand when to use () vs '' vs "".


Solution

  • $FormName = ($formChangeMe.Text | out-string).Trim() - Thanks to Matt!!