Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

PowerShell Add-Item...Access Denied

$
0
0

Hey guys,

So, I'm new to Powershell, so I have no idea what's going on.

I'm trying to make a script to set up all the things we need for new users. Here's the code that I'm having trouble with...

$first = Read-Host 'What is the first name?'
$last = Read-Host 'What is the last name?'
$name = Read-Host 'What is the username?'
$pass = "Password!"
$UserFolder = "D:\User Folders\Meltzer\$name"
New-Item -Path $UserFolder -ItemType directory

Everything works, up until the last line. Then, it gives me this-

New-Item : Access to the path 'shaering' is denied.

At C:\Users\SHaering\desktop\Test.ps1:10 char:9
+ New-Item <<<< $UserFolder -ItemType directory
+ CategoryInfo : PermissionDenied: (D:\User Folders\Meltzer\shaering:String) [New-Item], Unauthorized
ssException
+ FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

I've tried using -Force, I've tried using -Credentials, and I'm kind of stuck. I think it has something to do with the :String tacked onto the end, but I really don't know. Anyone have any ideas? Thanks in advance!


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>