Reputation: 1769
I am facing a strange situation. I am trying to create a directory structure in C: drive, but new directory structure gets created from where i am running my powershell script, I don't know why is this happening.
$new_folder='C:\new_folder'
new-item $new_folder -type directory
If I run the script from desktop , new folder gets created on desktop. Can someone please help
Upvotes: 0
Views: 1094
Reputation: 214
I can't replicate the problem to see if this works better but it may be worth a try:
$new_foldername = 'new_folder'
$new_folderpath = 'C:\'
New-Item -Name $new_foldername -Path $new_folderpath
Upvotes: 1
Reputation: 6940
It's a good practice to set ExecutionPolicy for your scripts, because when you are trying to access such resources (as C:\ in your case), you'll not have to worry about it.
Also I had some issues with relative path access to files/folders in C:\ and I had to use Resolve-Path in order to get script back-on-track.
Upvotes: 0