# --------------------------------------------------------------------------------------------------- # # Microsoft PowerShell Source File # NAME: SetGCrole.ps1 # # AUTHOR: Adam Bell, www.leadfollowmove.com # DATE : 12/03/2007 # # PURPOSE: Define Global Catalog functionality on a DC # # COMMENT: Best viewed in Notepad2 # Sample code only. Educational purposes only. # # --------------------------------------------------------------------------------------------------- # Script globals and constants.. # --------------------------------------------------------------------------------------------------- function set-GCrole # --------------------------------------------------------------------------------------------------- { # Inputs: 1) name of the server # 2) "enable" or "disable" keyword # Objective: 1) Enable or disable the GC role on the nominated server # Returns: 1) nada. Param ( $serverName, $IsGC = "enable" ) $dse = [adsi]("LDAP://"+$Servername+"/RootDSE") $ntds = [adsi]("LDAP://"+$dse.dsServiceName) # 1 = enable, 0 or nothing = disable If ($IsGC -eq "disable") { $ntds.options = 0 } else { $ntds.options = 1 } $ntds.SetInfo() } # --------------------------------------------------------------------------------------------------- # Example of (simple) Command line argument checking: If ($Args.count -ne 2) { write-host "You need to provide the Name of the DC," write-host "and the ""enable"" or ""disable"" keyword." write-host "example: ""server1"" ""enable""" write-host exit } # Example calling statement: Set-GCrole $Args[0] $args[1]