Hi all,
I am trying to perfect my server installation script, which runs a bunch of tasks on every new machine. The script is runned under a local admin account which prompts for domain credentials. Everything is working great. I am trying to create a folder on our NAS and set modify permissions on it. however the variables are not working. I have tried to run all the commands using the ; separator. Below is part of the script that I am using.
$NASfolder is the path of the folder on the NAS
$cred is are the domain credentials. Can someone help me?
Invoke-Command -ComputerName server.domain.local -Credential $cred {New-Item -Path "P:\P" -Name "$Using:NASfolder" -ItemType "directory"}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Acl = Get-Acl P:\P\"$Using:NASfolder"}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule("Domain\User", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Acl.Setaccessrule($Ar)}
Invoke-Command -ComputerName server.domain.local -Credential $cred {Set-Acl P:\P\"$Using:NASfolder" $Acl}