title: Set share permissions to Everyone FullControl with CIM CmdLets
body: <p>We're trying to write a function for a Windows server 2008 machine that needs to remove all the current trustees from the ACL of the share permissions and add the group <code>Everyone</code> with <code>FullControl</code> access. It would be great if we could use the faster CIM CmdLets for this instead of WMI.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>$ShareName = 'Folder'
  
  $trustee = New-CimInstance (Get-CimClass Win32_Trustee) -ClientOnly
  $trustee.Domain = $null
  $trustee.Name = 'EVERYONE'
  
  $ace = New-CimInstance (Get-CimClass Win32_ACE) -ClientOnly
  $ace.AccessMask = [Uint32][System.Security.AccessControl.FileSystemRights]::FullControl
  $ace.AceFlags = [Uint32][System.Security.AccessControl.AceFlags]::None
  $ace.AceType = [Uint32][System.Security.AccessControl.AceType]::AccessAllowed
  $ace.Trustee = $trustee
  
  $sd = New-CimInstance (Get-CimClass Win32_SecurityDescriptor) -ClientOnly
  $sd.DACL = $ace
  $sd.group = $trustee
  $sd.owner = $trustee
  
  $lss = Get-CimInstance -ClassName Win32_LogicalShareSecuritySetting -filter "Name='$ShareName'"
  Invoke-CimMethod -InputObject $lss -MethodName SetSecurityDescriptor -Arguments @{Descriptor = $sd}
  </code></pre>
  
  <p>A part of the <a href="https://books.google.co.uk/books?id=CxlKDwAAQBAJ&amp;pg=PA280&amp;lpg=PA280&amp;dq=SetSecurityDescriptor+cimmethod&amp;source=bl&amp;ots=HkXcZxRzE5&amp;sig=wlGFUCTx49JchBlED46K2r5YOw0&amp;hl=en&amp;sa=X&amp;ved=0ahUKEwjEjpL0soLcAhUFXRQKHQ9TBiAQ6AEIPDAD#v=onepage&amp;q&amp;f=false" rel="nofollow noreferrer">code</a> was found here.</p>
  
  <p>When executing the last line:</p>
  
  <pre><code>Invoke-CimMethod -InputObject $lss -MethodName SetSecurityDescriptor -Arguments @{Descriptor = $sd}
  </code></pre>
  
  <p>The output <code>ReturnValue 21</code> is generated. After some Googling it appears to be about an <a href="https://msdn.microsoft.com/en-us/library/aa393592(v=vs.85).aspx" rel="nofollow noreferrer">Invalid parameter</a>. But we don't see what we're missing here...</p>