Create new folder using New-Item

Topics: Archive - General
Sep 18, 2014 at 7:16 PM
I am a beginner of powershell, came across this little app and have started to use it. It works well for me until I have to do something a little outside the box then it gets a bit tricky.

I came across this post:
https://psappdeploytoolkit.codeplex.com/discussions/471396

Which kinda what I was looking for accept my files are going into Appdata\

I tried just using it and modifying it for my needs and it does not create the folder, but it attempts to copy the file. Because it continues to go without stopping, it installs the app.

I need to be able to create the folder in \AppData\Roaming\Folder1\Folder2

Then copy an .xml file from the Appdeploy Files folder to \AppData\Roaming\Folder1\Folder2

Then install the .msi file (which installs fine)

I tried:
New-Item -ItemType Directory -Force -Path "C:\Users\$($user.Name)\AppData\Roaming\Folder1\Folder2\"
    Copy-File -Path "$dirFiles\config_update.xml" -Destination "C:\Users\$($user.Name)\AppData\Roaming\Folder1\Folder2\config_update.xml"
But that didn't work properly.

Then I tried to modify the one in the post to create the folder:
    If (!(Test-Path -Path "C:\Users\$($user.Name)\AppData\Roaming\Folder1\Folder2\" -ErrorAction SilentlyContinue )) { New-Item "C:\Users\$($user.Name)\AppData\Roaming\Folder1\Folder2\" -Type Directory -ErrorAction SilentlyContinue | Out-Null }
But it also does not work. I am sure this is something simple and I Will continue to try multiple things, but thought I would ask while I am trying/learning.
thanks
Sep 18, 2014 at 7:41 PM
I figured it out...

My issue was the $($user.Name). I changed it to $env:Username and everything looks to be working.

So now I have:
If (!(Test-Path -Path "C:\Users\$env:Username\AppData\Roaming\Folder1\Folder2\" -ErrorAction SilentlyContinue )) { New-Item "C:\Users\$env:Username\AppData\Roaming\Folder1\Folder2\" -Type Directory -ErrorAction SilentlyContinue | Out-Null }
Copy-File -Path "$dirFiles\config_update.xml" -Destination "C:\Users\$env:Username\AppData\Roaming\Folder1\Folder2\config_update.xml"