Create a partition and set the ACL
i want standardize post-installation tasks powershell , running issues creation of partitions , configuration of security afterwards. way have found create partition in powershell is use diskpart.exe using this:
#start script #############
$driveconfig = @"
select disk 1
create partition primary noerr
format fs=ntfs quick
assign letter=d
"@
$driveconfig | diskpart
$path = "d:\"
$d_drive = get-acl $path
$rule = new-object system.security.accesscontrol.filesystemaccessrule("everyone","fullcontrol", "containerinherit, objectinherit", "none", "allow")
$d_drive.removeaccessruleall($rule)
set-acl $path $d_drive
#end script #############
when though, appears nt authority\system built in account gets set owner, , following error:
set-acl : security identifier not allowed owner of object.
@ line:1 char:8
+ set-acl <<<< $path $d_drive
+ categoryinfo : invalidoperation: (d:\:string) [set-acl], invalidoperationexception
+ fullyqualifiederrorid : system.invalidoperationexception,microsoft.powershell.commands.setaclcommand
tried use setowner fix this, appears require user privilege needs additional libraries not included on stock system. if change owner manually administrators group, problem goes away, trying avoid manual intervention, , avoid adding libraries server needed 1 line of code.
is there way create disk or set permissions avoid problem?
to change owner administrators.
1) takeown
Windows Server > Windows PowerShell
Comments
Post a Comment