I'm trying to create a powershell script that part of it creates a SMB share on our file server. I first tried doing with by entering a PSSession, but the commands after the PSSession never run. It's as if it doesn't enter the PSSession until the after the script runs. So I looked at the invoke-command. I first started off by using
Invoke-Command -ComputerName servername -Credential $cred {
G:
cd $project_folder
mkdir $username
New-SmbShare -Name $username -Path "G:\home\"+$username -ChangeAccess "NTGROUP\$username" -FullAccess "domain\Domain Admins"
}
However, this doesn't work as I get access denied and that -Path is null. I tried many different ways to specify what the path is. I even put the new-smbshare in to a variable outside of the invoke-command and just ran the variable. Doesn't help. I know I need to run the command as administrator, but the rest of the script won't work if I run the whole thing as administrator. So I guess I need a way to run just this one part as administrator and fix the -path part. I was looking at the start-process command, but it seems that works best if you're calling another script. I'm trying to keep everything in one script if possible. Any ideas??