Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Define the user who is to be given access to this printer and get the group's security principal details:
      $GroupName = 'Sales Group'
      $Group = New-Object -Typename 
Security.Principal.NTAccount `
-Argumentlist $GroupName
  1. Next, get the group's SID:
       $GroupSid = $Group.Translate([Security.Principal.
Securityidentifier]).Value
  1. Now define the SDDL that gives this user access to the printer:
    $SDDL = 'O:BAG:DUD:PAI(A;OICI;FA;;;DA)' +
            '(A;OICI;0x3D8F8;;;$GroupSid)'
  
  1. Display the details:
      'Group Name : {0}' -f $GroupName
      'Group SID : {0}'  -f $GroupSid
      'SDDL : {0}'       -f $SDDL
  1. Get the Sales Group printer object:
      $SGPrinter = Get-Printer -Name SGCP1
  1. Set the Permissions:
      $SGPrinter | Set-Printer -Permission $SDDL