All very easy with Windows PowerShell ...
New-Computer -Domain home.lab -Credential HOME\Administrator -Restart
Provide the password when prompted and wait for the machine to restart.
Easy easy easy .....
New-Computer -Domain home.lab -Credential HOME\Administrator -Restart
Get-NetAdapter
![]() |
| Get-NetAdapter Results |
New-NetIPAddress -IPAddress 192.168.33.10 ` -Default Gateway 192.168.33.1 ` -AddressFamily IPv4 ` -PrefixLength 24 ` -InterfaceIndex 19
![]() |
| New-NetIPAddress Results |
Set-DnsClientServerAddress `
-ServerAddress 192.168.33.2 `
-InterfaceIndex 19
Rename-Computer -NewName LABSVR2 -Restart
![]() |
| Default auditing on the root of a W2K12 Active Directory |
![]() |
| Auditing on the root of the domain after the script has run |
#------------------------------------------------------
# | File : ADDSAuditSettings.ps1
# |
# | Purpose : Configures extra auditing (SACLs) at for the
# | new domain
# |
# | Usage : PowerShell.exe -FILE .\ADDSAuditSettings.ps1
#------------------------------------------------------
# |
# | Author: JustAnotherTechnicalBlog
# | Creation Date: 26 April 2013
# |
# |
# | Maintenance History
# | -------------------
# |
# | Version: 1.00 2013-04-26 Initial Version JustAnotherTechnicalBlog
# |
# |
#------------------------------------------------------
# Clear the error variable
#------------------------------------------------------
$error.clear()
# Import the ActiveDirectory PowerShell Module if required
#------------------------------------------------------
if (-not (Get-Module ActiveDirectory))
{
Import-Module ActiveDirectory
}
# This fuction takes a schema GUID ID and a security
# principal and enables a new SACL entry so deletions
# of target object type by the specified security
# principal will be audited
#------------------------------------------------------
Function AuditDeletions {
Param (
[Parameter(Mandatory=$true)]
[system.guid]$SchemaIDGUID,
[Security.Principal.NTAccount]$SecurityPrincipal
)
# Get the DN for the current domain
#------------------------------------------------------
$dn = (Get-ADDomain).DistinguishedName
# Get the current ACLs for the root of the domain
#------------------------------------------------------
$acl = Get-ACL -Audit -Path AD:\$dn
# Build the new SACL rule.
# This rule will enable auditing of succesful deletion
# of our target object. The rule will be inherited
# throughout the domain
#------------------------------------------------------
$Rule = New-Object System.DirectoryServices.ActiveDirectoryAuditRule `
$SecurityPrincipal, `
"DeleteChild", `
"Success", `
$SchemaIDGUID, `
"All"
# Add the new audit rule to the ACL we
# opened earlier
#------------------------------------------------------
$acl.AddAuditRule($Rule)
# Commit the new audit rule
#------------------------------------------------------
Set-ACL -Path AD:\$dn -AclObject $acl
}
# To work with AD objects we need the relevent schema
# ID GUIDs. variables to hold these:
#------------------------------------------------------
$ComputerSchemaIDGUID = "bf967a86-0de6-11d0-a285-00aa003049e2"
$GroupSchemaIDGUID = "bf967a9c-0de6-11d0-a285-00aa003049e2"
$UserSchemaIDGUID = "bf967aba-0de6-11d0-a285-00aa003049e2"
# The AuditDeletions function above requires a security
# principal. user/group we want to audit?
#------------------------------------------------------
$who = "Everyone"
# Put the AuditDeletions function to use ....
#------------------------------------------------------
AuditDeletions $ComputerSchemaIDGUID $who
AuditDeletions $GroupSchemaIDGUID $who
AuditDeletions $UserSchemaIDGUID $who
# Basic error handling
#------------------------------------------------------
If ($error)
{
Write-Host "Audit setting configurations failed"
Exit 1003
}
Else
{
Write-Host "Audit setting configurations completed OK"
}
#-------------------------------------------------------------------
# | File : NewChildDomain.ps1
# |
# | Purpose : Installs the first Domain Controller in a child domain,
# | thus creating the new domain
# | - Designed to be run from a Configuration Manager OSD
# | task sequence
# | - Designed for Windows Server 2012 environments
# | - Reboot handled by task sequence
# |
# | Usage : PowerShell.exe -FILE .\NewChildDomain.ps1
#-------------------------------------------------------------------
# |
# | Author: JustAnotherTechnicalBlog
# | Creation Date: 23 April 2013
# |
# |
# | Maintenance History
# | -------------------
# |
# | Version: 1.00 2013-04-23 Initial Version JustAnotherTechnicalBlog
# |
# |
#-------------------------------------------------------------------
# Clear the error variable
#-------------------------------------------------------------------
$error.clear()
# Import the ActiveDirectory PowerShell Module if required
#-------------------------------------------------------------------
if (-not (Get-Module ActiveDirectory))
{
Import-Module ActiveDirectory
}
# Here we get access to the Task Sequence variables
#-------------------------------------------------------------------
$objTSenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
# Grab the data we need from the task sequence variables
#-------------------------------------------------------------------
$strTSNetBIOSName = $objTSenv.Value("RoleVariable1")
$strTSDomainName = $objTSenv.Value("RoleVariable2")
$strTSPrntNBName = $objTSenv.Value("RoleVariable3")
$strTSPrntDmnName = $objTSenv.Value("RoleVariable4")
$strTSPrntDmnAcct = "$strTSPrntNBName\" + $objTSenv.Value("RoleAccount2")
$strTSDNSAccount = "$strTSPrntNBName\" + $objTSenv.Value("RoleAccount3")
# Convert our password to the data type required by Install-ADDSDomain
#-------------------------------------------------------------------
$secstrSafeModePassword = $objTSenv.Value("RoleAccountPassword1") | `
ConvertTo-SecureString -asPlainText -Force
# Convert our accounts and passwords strings to the data type required
# by Install-ADDSDomain
#-------------------------------------------------------------------
$secstrDomainPassword = $objTSenv.Value("RoleAccountPassword2") | `
ConvertTo-SecureString -asPlainText -Force
$DomainCreds = New-Object `
System.Management.Automation.PSCredential("$strTSPrntDmnAcct",$secstrDomainPassword)
$secstrDNSPassword = $objTSenv.Value("RoleAccountPassword3") | `
ConvertTo-SecureString -asPlainText -Force
$DNSCreds = New-Object `
System.Management.Automation.PSCredential("$strTSDNSAccount",$secstrDNSPassword)
# Install our first forest Domain Controller, creating a new forest
#-------------------------------------------------------------------
Install-ADDSDomain `
-Force `
-NoRebootOnCompletion `
-CreateDNSDelegation `
-DomainType Child `
-DomainMode Win2012 `
-ParentDomainName "$strTSPrntDmnName" `
-NewDomainNetBIOSName "$strTSNetBIOSName" `
-NewDomainName "$strTSDomainName" `
-SafeModeAdministratorPassword $secstrSafeModePassword `
-DNSDelegationCredential $DNSCreds `
-Credential $DomainCreds
# Basic error handling
#-------------------------------------------------------------------
If ($error)
{
Write-Host "Child domain creation failed"
Exit 1001
}
Else
{
Write-Host "Child domain created successfully"
![]() |
| Task Sequence Snippet: Active Directory Installation |
![]() |
| Installing an Active Directory Child Domain with Windows PowerShell |
#----------- PowerShell.exe -COMMAND Install-WindowsFeature -Name AD-Domain-Services ` -IncludeManagementToolsThe code above does not create an domain controller. It just installs the Active Directory Domain Services role. Other steps in the task sequence see the server promoted to be a domain controller.
![]() |
| Task Sequence Snippet: Active Directory Installation |
![]() |
| Installing the Active Directory Domain Services Role with Windows PowerShell |
# ------------------------------------------------------------------
# Purpose: Applies some registry settings, mostly related to the
# problem identified in KB2419357. It also makes a change to WDS
# network settings to improvea packet fragmentation issue identified
# during testing of multicast with SCCM
#
# Usage : powershell.exe -file .\wdsconfig.ps1
#
# Version 1.0
#
# Maintenance History
# ------------------------------------------------------------------
# Version - Date - Change - Author
# ------------------------------------------------------------------
# 1.0 21/11/12 Script Created JustAnotherTechnicalBlog
#
# ------------------------------------------------------------------
# Set variables
$WDSRegRoot = "HKLM:System\CurrentControlSet\Services\WDSServer"
$WDSService = "Windows Deployment Services Server"
# Write the required SCCM options to the WDS configuration settings
# to the registry
If (Test-Path $WDSRegRoot\Parameters)
{
Set-ItemProperty -Path $WDSRegRoot\Parameters -Name McStartAddr `
-Value "239.10.10.10"
Set-ItemProperty -Path $WDSRegRoot\Parameters -Name McEndAddr `
-Value "239.10.10.10"
Set-ItemProperty -Path $WDSRegRoot\Parameters -Name UdpStartPort `
-Value "63000"
Set-ItemProperty -Path $WDSRegRoot\Parameters -Name UdpEndPort `
-Value "64000"
}
# Tune the network settings for the WDS server to reduce likelihood
# of packet fragmentation
If (Test-Path $WDSRegRoot\Providers\WDSMC\Protocol)
{
Set-ItemProperty -Path $WDSRegRoot\Providers\WDSMC\Protocol `
-Name ApBlockSize `
-Value 1385
}
# Restart the Windows Deployment Services Server service
if (Get-Service $WDSService -ea SilentlyContinue)
{
Restart-Service -displayname $WDSService
}
#
#
# Purpose: Prompts end user to restart if Windows is waiting for a restart after
# patching
#
# Usage : powershell.exe -file .\PatchingRestartNagBalloon.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 25/06/12 Script Created justanothertechnicalblog
#
#
$SoftwareUpdateRestartStatus = New-Object -ComObject "Microsoft.Update.SystemInfo"
$IsRebootRequired = $SoftwareUpdateRestartStatus.RebootRequired
If ($IsRebootRequired -eq $True)
{
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
$notification = New-Object System.Windows.Forms.NotifyIcon
#Define the icon for the system tray
$notification.Icon = [System.Drawing.SystemIcons]::Information
#Display title of balloon window
$notification.BalloonTipTitle = “Software Updates”
#Type of balloon icon
$notification.BalloonTipIcon = “Info”
#Notification message
$notification.BalloonTipText = “Software updates have been installed on your computer. Please save your work and restart your computer as soon as possible”
#Make balloon tip visible when called
$notification.Visible = $True
#Call the balloon notification
$notification.ShowBalloonTip(0)
start-sleep -s 10
#Make balloon tip invisible when called
$notification.Visible = $False
Exit-PSSession
}
Else
{
Exit-PSSession
}
#
#
# Purpose: Prompts end user to contact the Service Desk and opens IE to the
# Service Desk home page
#
# Usage : powershell.exe -f .\ActiveDirectoryOUNagBalloon.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 25/06/12 Script Created justanothertechnicalblog
#
#
function Show-BalloonTip
{
# Requires -Version 2.0
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNull()]
[String]$BalloonTipText,
[Parameter(Position = 1)]
[String]$BalloonTipTitle = 'PowerShell Event Notificaton',
[Parameter(Position = 2)]
[ValidateSet('Error', 'Info', 'None', 'Warning')]
[String]$BalloonTipIcon = 'Info'
)
end
{
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[Windows.Forms.ToolTipIcon]$BalloonTipIcon = $BalloonTipIcon
$NotifyIcon = New-Object Windows.Forms.NotifyIcon -Property @{
BalloonTipIcon = $BalloonTipIcon
BalloonTipText = $BalloonTipText
BalloonTipTitle = $BalloonTipTitle
Icon = [Drawing.Icon]::ExtractAssociatedIcon((Get-Command powershell).Path)
Text = -join $BalloonTipText[0..62]
Visible = $true
}
switch ($BalloonTipIcon)
{
Error {[Media.SystemSounds]::Hand.Play()}
Info {[Media.SystemSounds]::Asterisk.Play()}
None {[Media.SystemSounds]::Beep.Play()}
Warning {[Media.SystemSounds]::Exclamation.Play()}
}
$NotifyIcon.ShowBalloonTip(0)
switch ($Host.Runspace.ApartmentState)
{
STA
{
$null = Register-ObjectEvent -InputObject $NotifyIcon -SourceIdentifier "BalloonTipClicked_event" -EventName BalloonTipClicked -Action{
#Write-Host "Starting IE"
Start-Process 'c:\Program Files\Internet Explorer\iexplore.exe' -ArgumentList 'http://justanothertechnicalblog.blogspot.com.au/' -WindowStyle Maximized -Verb Open
$Sender.Dispose()
$global:clicked = $true
Unregister-Event $EventSubscriber.SourceIdentifier
Remove-Job $EventSubscriber.Action
}
}
default
{
continue
}
}
}
}
Get-EventSubscriber | Unregister-Event | Out-Null
#Write-Host $Host.Runspace.ApartmentState
Show-BalloonTip "Some location information for this computer has not been configured correctly. Please contact the Service Desk resolve this issue. This is a minor issue and should not impact your use of this machine" "Computer Configuration Warning" "Warning"
$global:clicked = $false
$timeOut=20 #20 Seconds
for($timeOut;$timeOut -gt 0;$timeOut--)
{
if($global:clicked)
{
break;
}
#Write-Host "Sleeping 1 second"
Start-Sleep -Milliseconds 1000
}
' ----------------------------------------------------------------------
'
' Purpose: Prompts end user to contact the Service Desk and opens IE to the
' Service Desk home page
'
' Usage : cscript.exe RunPowerShellScriptHidden.vbs mypath\myscript.ps1
'
' Version 1.0
'
' Maintenance History
' ----------------------------------------------------------------------
' Version - Date - Change - Author
' ----------------------------------------------------------------------
' 1.0 25/06/12 Script Created justanothertechnicalblog
'
'
Option Explicit
'Variables
Dim oShell, ScriptName, appCmd
' Read target script path from command line argument or echo usage details if arguments are wrong
If WScript.Arguments.Count = 1 Then
ScriptName = WScript.Arguments.Item(0)
Else
Wscript.Echo "Usage: RunPowerShellScriptHidden path\powershellscript"
Wscript.Quit
End If
'Create objects
Set oShell = CreateObject("WScript.Shell")
' Build the command line
appCmd = "PowerShell.exe -file " + ScriptName
'Run the PowerShell script now
oShell.Run appCmd, 0, false
#
#
# Purpose: Enables Wake on LAN (WOL) settings on active wired network cards
#
# Usage : powershell.exe -f .\EnableWOL.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 18/06/12 Script Created justanothertechnicalblog
#
#
$nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' AND PhysicalAdapter = 'true'"
foreach ($nic in $nics)
{
$nicName = $nic.Name
Write-Host "--- Enable `"Allow the computer to turn off this device to save power`" on $nicName ---"
$nicPower = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPower.Enable = $True
$nicPower.psbase.Put()
Write-Host "--- Enable `"Allow this device to wake the computer`" on $nicName ---"
$nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPowerWake.Enable = $True
$nicPowerWake.psbase.Put()
Write-Host "--- Enable `"Only allow a magic packet to wake the computer`" on $nicName ---"
$nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicMagicPacket.EnableWakeOnMagicPacketOnly = $True
$nicMagicPacket.psbase.Put()
}
# ----------------------------------------------------------------------
#
# Purpose: Enables Wake on LAN (WOL) settings on active wired network cards
#
# Usage : powershell.exe -f .\EnableWOL.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 18/06/12 Script Created justanothertechnicalblog
# 2.0 04/07/12 Updated to exclude justanothertechnicalblog
# Wireless/WiFi/Bluetooth
# Get all physical ethernet adaptors
$nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' `
AND PhysicalAdapter = 'true' `
AND NOT Description LIKE '%Centrino%' `
AND NOT Description LIKE '%wireless%' `
AND NOT Description LIKE '%WiFi%' `
AND NOT Description LIKE '%Bluetooth%'"
foreach ($nic in $nics)
{
$nicName = $nic.Name
Write-Host "--- Enable `"Allow the computer to turn off this device to save power`" on $nicName ---"
$nicPower = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPower.Enable = $True
$nicPower.psbase.Put()
Write-Host "--- Enable `"Allow this device to wake the computer`" on $nicName ---"
$nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPowerWake.Enable = $True
$nicPowerWake.psbase.Put()
Write-Host "--- Enable `"Only allow a magic packet to wake the computer`" on $nicName ---"
$nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicMagicPacket.EnableWakeOnMagicPacketOnly = $True
$nicMagicPacket.psbase.Put()
}