Skip to content

Instantly share code, notes, and snippets.

.SYNOPSIS
Script used to find all unlinked gpos, back them up and then delete them.
.DESCRIPTION
The script searches your logged on domain for unlinked GPO's. It then backs them up to a folder on the C:\. It will then remove them. It also creates a log file in the same directory.
.LINK
http://www.pixelrobots.com
#>
Enter-PSSession -ComputerName PIXEL-NANO01
Install-PackageProvider NanoServerPackage
Import-PackageProvider NanoServerPackage
Find-nanoserverPackage -name *
Install-NanoServerPackage -name Microsoft-NanoServer-IIS-Package -Culture en-us
Set-ClusterQuorum -CloudWitness -AccountName <storageAccountName> -AccessKey <StorageAccountAccessKey>
# Install ADDS and all management tools
Add-WindowsFeature -Name “ad-domain-services” -IncludeAllSubFeature -IncludeManagementTools
# Add Domain Controller to existing Forest
write-Host "Add Dc to existing Forest"
$domainname = Read-Host "Enter Domain Name you want to join eg: ad.contoso.com"
$sitename = read-host "Enter name of site to join. eg: Default-First-Site"
Import-Module ADDSDeployment
Install-ADDSDomainController `
-NoGlobalCatalog:$false `
-CreateDnsDelegation:$false `
### Add Reverse DNS Looup Zone
$rDNS = read-host "Enter Reverse DNS network ID eg: 10.10.10.0/24"
Add-DnsServerPrimaryZone -NetworkId:$rDNS -ReplicationScope Forest
# Add subnet to sites and service
Write-Host "Add Subnet to Site"
$Subnet = read-host "Enter subnet in format 10.10.10.0/24"
$desc = read-host "Enter description eg: 10.10.10.0/255.255.255.0"
New-ADObject -Name:$subnet -Type subnet -Description:$desc -OtherAttributes @{location="Yellow-Pixel";siteObject="CN=Yellow-Pixel,CN=Sites,CN=Configuration,DC=ad,DC=testpixels,DC=co,DC=uk"} -Path "CN=Subnets,CN=Sites,CN=Configuration,DC=ad,DC=testpixels,DC=co,DC=uk"
# Change Default-First-Site-Name
Write-Host "Change Name of Default-First-Site"
$Sitename = read-host "Enter new site name to replace Default-First-Site"
$configNCDN = (Get-ADRootDSE).ConfigurationNamingContext
$siteContainerDN = ("CN=Sites," + $configNCDN)
$siteDN = "CN=Default-First-Site-Name," + $siteContainerDN
Get-ADObject -Identity $siteDN | Rename-ADObject -NewName:$sitename
# Create New Forest, add Domain Controller
write-Host "Create Forest and Promote 1st DC"
$domainname = Read-Host "Enter Forest Name eg: ad.pixelrobots.co.uk"
$netbios = Read-Host "Enter Netbios Name eg: pixelrobots"
Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\NTDS" `
-DomainMode "7" `
-DomainName:$domainname `
# Install ADDS and all management tools
Write-Host "Installing ADDS"
Add-WindowsFeature -Name “ad-domain-services” -IncludeAllSubFeature -IncludeManagementTools -verbose
#Find who has the FSMO Roles
netdom query fsmo
#Move FSMO Roles
Move-ADDirectoryServerOperationMasterRole -Identity PIXEL-DC03 -OperationMasterRole SchemaMaster, DomainNamingMaster, PDCEmulator, RIDMaster, InfrastructureMaster
#Check that the move went well
Netdom query fsmo