Update-GphSchemaCache.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Update-GphSchemaCache
{
  <#
      .SYNOPSIS
      Updates the AD Schema Cache.
 
      .DESCRIPTION
      This Cmdlet refreshes the Schema Cache. It is a helper-Function for Add-GphGpoDefaultPermissions to
      speed up the Permission Canche for New GPOs.
 
      .EXAMPLE
      Upddate-GphSchemaCache
      Updates the AD Schema Cache
       
      .NOTES
      Author: Holger Voges
      Date: 2018-11-16
      Version: 1.0
  #>

  [CmdletBinding()]
  param()
  
  Try 
  {
    $SchemaMaster = (Get-ADForest).SchemaMaster.Split('.')[0]
    $RootDSE = [ADSI] "LDAP://$SchemaMaster/RootDSE"
    $RootDSE.put("SchemaUpdateNOW",1)
    $RootDSE.SetInfo()
    Write-Information -MessageData 'Update successfull'
  }
  Catch
  {
    $_.Exception.Message
  }
}