PowerShell Cmdlets for Windows Server 2012

Check out some important powershell cmdlets that can be used to do some cool tasks in Windows Server 2012. Need to replace only those parts which are in bold and italics, as required.

Install GUI in Windows Server 2012

  • Install-WindowsFeature Server-Gui-Shell
  • Install-WindowsFeature Server-Gui-Mgmt-Infra

Uninstall GUI

  • Uninstall-WindowsFeature Server-Gui-Shell –Remove

Rename Computer

  • Rename-Computer ComputerName
  • Restart-Computer

Installing server roles and features

  • Install-WindowsFeature WindowsFeature

Install specific roles and features of a server on a different server

  • Install-WindowsFeature -ConfigurationFilePath Path of XML file

XML file is the file that gets saved in the last step of Add Roles and Features Wizard.

Active Directory Related Commandlets

Validate conditions for AD

  • Test-ADDSDomainControllerInstallation -Domainname DomainName -SafeModeAdministratorPassword <SecureString>

Install a new DC

  • Install-ADDSDomainController -DomainName DomainName -SafeModeAdministratorPassword (read-host -prompt “Password” -assecurestring)

Install ADDS, DNS and create a new domain in a new forest

  • Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
  • Install-ADDSForest -DomainName DomainName

Create new user in AD

  • New-ADUser UserName AccountName AccountName -AccountPassword (read-host “Set user password” -assecurestring) -name “AccountName” -enabled $true -PasswordNeverExpires $true -ChangePasswordAtLogon $false

Create a new replication site

  • New-ADReplicationSite -Name “SiteName

Create a new AD site link

  • New-ADReplicationSiteLink -Name “SiteLinkName” -SitesIncluded Site1,Site2 -Cost 100 -ReplicationFrequencyInMinutes 15 -OtherAttributes @{‘options’=1}

This command sets the Cost, ReplicationFrequency (In Minutes) and enables change notification on the new object.

Check AD replication

  • Get-ADReplicationUpToDatenessVectorTable -Target Target -Scope Scope -Partition *

Target can be either DC or the Site name or the domain. Based on Target, scope differs as Server for DC, Site for Site name and Domain for Domain name target. * indicates all the partitions and can be replaced with any other such as Default, Configuration, Schema etc.

Static IP address configuration with DNS

  • New-NetIPAddress -IPAddress xx.x.x.x -InterfaceAlias “Name” -DefaultGateway xx.x.x.x -AddressFamily IPv4 -PrefixLength 24
  • Set-DnsClientServerAddress -InterfaceAlias “Name” -ServerAddresses xx.xx.xx.x

Join to a domain

  • Add-Computer -DomainName DomainName
  • Restart-Computer

Display existing recovery point

  • Get-ComputerRestorePoint

Restore to a specific sequence number

  • Restore-Computer SequenceNumber

Check out Hyper-V related PowerShell cmdlets here..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s