Guest User

adfunctions.ps1

a guest
Oct 11th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####################################################################################
  2. ### AD Functions Library, v.1.1
  3. ### Efimov (ge][) Gennady, http://gexeg.blogspot.com/
  4. ####################################################################################
  5.  
  6. function GetForest($forestname){
  7.     $ctx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
  8.         [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname)
  9.  
  10.     $forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetForest($ctx)
  11.     return $forest
  12. }
  13.  
  14. function GetConfigNC($BindName){
  15.     $rootDSE = [adsi]$("LDAP://$BindName/RootDSE")
  16.     return $rootDSE.configurationNamingContext.Value.ToString()
  17. }
  18.  
  19. function GetForestContext($forestName, $userName, $Password){
  20.     if (-not $userName){
  21.         return New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
  22.             [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname)
  23.     }
  24.     else {
  25.         return New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
  26.             [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname, $userName, $Password)
  27.     }
  28. }
  29.  
  30. function GetScheduleInfo($schedule){
  31.     $i_arr = @()
  32.     if ($schedule.RawSchedule){
  33.         $startT = New-Object System.TimeSpan(0,0,0,0)
  34.         $current = $startT.Add("00:00:00")
  35.         for ($d = 0; $d -lt 7;$d++){
  36.             for($h = 0; $h -lt 24; $h++){
  37.                 for($m = 0; $m -lt 4; $m++){
  38.                     if (-not $schedule.RawSchedule[$d,$h,$m]){
  39.                         if ([System.TimeSpan]::Compare($startT, $current) -eq -1){
  40.                            
  41.                             $i_arr += [object]$(@($startT, $current.Subtract("00:00:01")))
  42.                         }
  43.                         $startT = $current.Add("00:15:00")
  44.                     }
  45.                     $current = $current.Add("00:15:00")
  46.                 }
  47.             }
  48.         }
  49.         if ([System.TimeSpan]::Compare($startT, $current) -eq -1){
  50.             $i_arr += [object]$(@($startT, $current.Subtract("00:00:01")))
  51.         }
  52.     }
  53.     return $i_arr
  54. }
  55.  
  56. function ScheduleToString($timespan_arr){
  57.     [string[]]$str = @()
  58.    
  59.     for($i = 0; $i -lt $timespan_arr.Length/2; $i++){
  60.         $str += @($timespan_arr[$i*2].ToString() + "-" + $timespan_arr[$i*2+1].ToString())
  61.     }
  62.     return "{" + [System.String]::Join(",", $str) + "}"
  63. }
  64.  
  65. function GetSiteOptionInfo($siteOption){
  66.     $opts = @(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024)
  67.     [string[]]$str = @()
  68.     foreach($op in $opts){
  69.         if (($siteOption -band $op) -eq $op){
  70.             $str += ([System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteOptions]$op).ToString()
  71.         }
  72.     }
  73.     return [System.String]::Join(",", $str)
  74. }
  75.  
  76. function GetUGMCSite($siteDE){
  77.    
  78.     $ntdsset = $siteDE.PSBase.Children.PSBase.Find("CN=NTDS Site Settings", "nTDSSiteSettings")
  79.     if ($ntdsset -and $ntdsset.PSBase.Properties.Item("msDS-Preferred-GC-Site")){
  80.         return [adsi]"LDAP://$($ntdsset.PSBase.Properties.Item(`"msDS-Preferred-GC-Site`").Value.ToString())"
  81.     }
  82.     else {
  83.         return $null
  84.     }
  85. }
  86.  
  87. function GetSiteLinkOptions($sitelink){
  88.     [string[]]$str = @()
  89.     $str += "DataCompressionEnabled: {0}" -f $sitelink.DataCompressionEnabled.ToString()
  90.     $str += "NotificationEnabled: {0}" -f $sitelink.NotificationEnabled.ToString()
  91.     $str += "ReciprocalReplicationEnabled: {0}" -f $sitelink.ReciprocalReplicationEnabled.ToString()
  92.     return [system.String]::Join(";", $str)
  93. }
  94.  
  95. function GetTrustOptions($trust){
  96.    
  97.     return "-"
  98. }
Advertisement
Add Comment
Please, Sign In to add comment