Category: Microsoft Windows PowerShell

Microsoft Windows Server 2012 R2 – Configure Network Time Protocol

You may use the following commands, run as an administrator in Windows PowerShell, to configure the Network Time Protocol (NTP) settings for Microsoft Windows Server 2012 R2. In this example, the NTP server to be configured is pool.ntp.org, which is a round-robin of NTP server.

w32tm /config /manualpeerlist:pool.ntp.org /syncfromflags:MANUAL
Stop-Service w32time
Start-Service w32tim

Enjoy!


Microsoft Windows Server 2012 R2 – Deleting a PTR Record

If you ever need to delete an individual pointer record (PTR) that is all capitalized and will not delete from the Microsoft Windows Server DNS graphical user interface (GUI) then use the example command below. The example below will delete the PTR record which corresponds to Internet Protocol (IP) address 192.168.25.100.

Remove-DnsServerResourceRecord -ZoneName “25.168.192.in-addr.arpa” -RRType “PTR” -Name “100”


Microsoft Windows Server 2012 R2 – Remote Reboot

You may use the following command to remotely reboot a server forcefully in (180) seconds running Windows Server 2012 R2.

shutdown /r /m \\<<<hostname>>> /f /t 180


Microsoft Windows Server 2012 R2 – Configure NIC Teaming

You may use the Microsoft Windows PowerShell (.ps1) script below to configure NIC teaming in Microsoft Windows Server 2012 R2. Additionally, you may modify the script to meet the needs of your specific environment.

<#
.SYNOPSIS
This script will configure NIC1 and NIC2 to (1) Gbps Full Duplex, disable NIC3 and NIC4, create NIC Team 1 and configure NIC Team 1 TCP/IP settings.
.DESCRIPTION
This script will automate the configuration of Microsoft Windows Server 2012 R2 NIC Teaming.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Tuesday, November 10, 2015.
#>

#Request the Internet Protocol (IP) address of the server
$IP_Address = Read-Host “What is the Internet Protocol (IP) address of the server?”

#Configure NIC1 and NIC2 to 1 Gbps Full Duplex
Set-NetAdapterAdvancedProperty NIC1 -DisplayName “Speed & Duplex” -DisplayValue “1.0 Gbps Full Duplex”
Set-NetAdapterAdvancedProperty NIC2 -DisplayName “Speed & Duplex” -DisplayValue “1.0 Gbps Full Duplex”

#Disable NIC3 and NIC4
Disable-NetAdapter -Name “NIC3” -Confirm:$false
Disable-NetAdapter -Name “NIC4” -Confirm:$false

#Create NIC Team 1
New-NetLbfoTeam -Name “Team 1” -TeamMembers NIC1,NIC2 -TeamNicName “TEAM 1” -TeamingMode SwitchIndependent -LoadBalancingAlgorithm Dynamic -Confirm:$false

#Configure NIC Team 1 TCP/IP settings
Get-NetAdapter -Name “Team 1” | Set-NetIPInterface -DHCP Disabled
Start-Sleep 5
Get-NetAdapter -Name “Team 1” | New-NetIPAddress -AddressFamily IPv4 -IPAddress $IP_Address -PrefixLength “XX” -Type Unicast -DefaultGateway “X.X.X.X”
Set-DnsClientServerAddress -InterfaceAlias “Team 1” -ServerAddresses “X.X.X.X”, “X.X.X.X”

#End of script


Microsoft Windows PowerShell – Starting a Service on a Remote Server

The following (2) commands may be used to verify the status of a service on a remote computer as well as start the service on the remote computer. Additionally, you may substitute the name value with the displayname value.

 

get-service -computername <<<INSERT>>> | where-object {$_.name -eq “<<<INSERT>>>”}

get-service -name <<<INSERT>>> -computername <<<INSERT>>> | set-service -status running


Microsoft Windows PowerShell – Command Reference

The list below contains a reference list of Microsoft Windows PowerShell commands.

  • Networking
    • List Network Adapters
      • Get-NetAdapter

Microsoft Windows Server 2012 R2 – Network Time Protocol Configuration

You may use the following Microsoft Windows PowerShell commands, as an administrator, to configure the network time protocol (NTP) servers for Windows Server 2012 R2 and sync a Windows client, such as Microsoft Windows 7, to the server. This example is using the well known NTP servers from the NTP Pool Project.

  • Server Configuration:
    • w32tm /config /manualpeerlist:”0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org” /syncfromflags:MANUAL
    • Stop-Service w32time
    • Start-Service w32time
  • Client Configuration:
    • w32tm /resync

Microsoft Windows PowerShell – Query a List of SAMAccountNames

The Microsoft PowerShell script below may be used to query a list of Microsoft Active Directory SAMAccountNames from a Notepad (.txt) file and output the Given Name and Enabled status in a CSV file.

 

#This scrip will query a list of SAMAccountNames from a notepad (.txt) file and provide the Name and Enabled status
#
#Provide the path to the Notepad (.txt) file tha contains the list of SAMAccountNames
$– USERS = Get-Content “<<File Path>>”
$– USERS | ForEach {Get-ADUser $_ -Properties * | Select SAMAccountName, Name, Enabled} | Export-CSV -Path “<<File Path>>”

 

Enjoy!


Microsoft Windows PowerShell – Systeminfo and System Boot Time

The systeminfo command in Microsoft Windows PowerShell will provide you with many statistics for your Windows server. If you’re ever looking for the servers uptime then you may use the following command:

systeminfo | find “System Boot Time”


Microsoft Windows PowerShell – List Installed Applications

This script will query a remote computer’s list of installed applications and provide the output in a file and directory of your choice.

Example: gwmi win32_product -ComputerName “Computer1” | out-file -filepath “<File Path>”