Author: Noel Alvarez

Microsoft Windows PowerShell – View Reboot and Uptime

The Microsoft Windows PowerShell script below will query a Windows hosts for the time it was rebooted and the time it completed it’s reboot.

<#
.SYNOPSIS
This script will request the hostname of a server then provide the time it was shutdown and completed it’s reboot.
.DESCRIPTION
This script will request the hostname of a server then provide the time it was shutdown and completed it’s reboot.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Friday, May 10, 2019.
#>

#Request the hostname of the server
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Message
Write-Host The date and time below indicate the time the server was shutdown -ForegroundColor Green

#Provide the uptime of the server
Get-EventLog -Logname System -ComputerName $HOSTNAME | Where-Object {$_.EventID -EQ 6006} | Select-Object -First 1

#Message
Write-Host The date and time below indicate the uptime of the server -ForegroundColor Green

#Provide the uptime of the server
Get-EventLog -Logname System -ComputerName $HOSTNAME | Where-Object {$_.EventID -EQ 6005} | Select-Object -First 1

#End of script


Microsoft Windows PowerShell – Get Host Architecture

You may use the following Microsoft Windows PowerShell script below to get the architecture, physical or virtual, of a Windows host on a network.

<#
.SYNOPSIS
This script will provide the architure (physical of virtual) of a host.
.DESCRIPTION
This script will provide the architure (physical of virtual) of a host.
.EXAMPLE
systeminfo /s $HOSTNAME | findstr /c:”Model:” /c:”Host Name”
.AUTHOR
Written by Noel Enrique Alvarez on Tuesday, April 23, 2019.
#>

#Requst the hostname of the host
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Provide the architure of the host
systeminfo /s $HOSTNAME | findstr /c:”Model:” /c:”Host Name”


Microsoft Windows 10 – False Duplicate IP Address Detected

At my existing employer, it was brought to my attention that a number of VMware virtual machines running the Microsoft Windows 10 operating system were randomly dropping off the network, upon reboot. Viewing the properties of the network adapter confirmed that they were assigned static IP addresses. However, running ipconfig from the command prompt showed that they were assigned 169.254.x.x IP addresses.

Upon reviewing the logs I found the following error message: “The system detected an address conflict for IP address 0.0.0.0 with the system having network hardware address XX-XX-XX-XX-XX-XX. Network operations on this system may be disrupted as a result.” The XX-XX-XX-XX-XX-XX is the MAC address of a Cisco switch.

In summary, the root cause of this is Windows 10 performing an ARP probe at the time as the Cisco switch performing an ARP probe in order to maintain the IP device-tracking cache during IP device tracking. The Windows 10 host believes another node on the network is probing the address it’s assigned and must treat it as an IP address conflict.

The solution is to disable gratuitous ARPs on the switch or in the Windows 10 operating system. We chose to disable the gratuitous ARP in the Windows 10 operating system.

Additionally, more information may be found using the links below.


VMware PowerCLI – Power On a Virtual Machine

You may use the VMware PowerCLI cmdlet below to power on a VMware virtual machine.

Start-VM -VM SERVER


VMware PowerCLI – Create a Snapshot

You may use the following VMware PowerCLI cmdlet to create a snapshot of a virtual machine (VM) in VMware.

New-Snapshot -VM HOSTNAME -Name “<<>>” -Description “<<>>”


VMware PowerCLI – Exit VMware ESXi Host out of Maintenance Mode

You may use the following VMware PowerCLI script to exit a VMware ESXi host out of maintenance mode.

<# .SYNOPSIS This script will exit a VMware ESXi host out of maintenance mode. .DESCRIPTION This script will exit a VMware ESXi host out of maintenance mode. .EXAMPLE Set-VMHost -VMhost HOST.DOMAIN.COM -State Connected. .AUTHOR Written by Noel Enrique Alvarez on Monday, April 15, 2019. #>

#Request the hostname of the VMware ESXi host
$HOSTNAME = Read-Host “What is the hostname of the VMware ESXi host?”

#Exit the VMware ESXi host out of maintenance mode
Set-VMHost -VMhost $HOSTNAME -State Connected

#End of script


VMware PowerCLI – Place VMware ESXi Host in Maintenance Mode

You may use the following VMware PowerCLI script to place a VMware ESXi host in maintenance mode.

<# .SYNOPSIS This script will place a VMware ESXi host in maintenance mode. .DESCRIPTION This script will place a VMware ESXi host in maintenance mode. .EXAMPLE Set-VMHost -VMhost HOST.DOMAIN.COM -State Maintenance. .AUTHOR Written by Noel Enrique Alvarez on Monday, April 15, 2019. #>

#Request the hostname of the VMware ESXi host
$HOSTNAME = Read-Host “What is the hostname of the VMware ESXi host?”

#Place the VMware ESXi host in maintenance mode
Set-VMHost -VMhost $HOSTNAME -State Maintenance

#End of script


Microsoft Windows PowerShell – Query Users on Remote Server

You may use the following Microsoft Windows PowerShell script to query a remote server and display any logged on users.

<# .SYNOPSIS This script will query a remote server and display user session information. .DESCRIPTION This script will query a remote server and display user session information. .EXAMPLE N/A. .AUTHOR Written by Noel Enrique Alvarez on Monday, April 15, 2019. #>

#Request the hostname of the server
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Query the remove server
query user /server:$HOSTNAME

#End of script


Microsoft Windows PowerShell – Reboot Multiple Servers

You may use the following Microsoft Windows PowerShell script to reboot multiple Microsoft Windows hosts on a network.

<# .SYNOPSIS This script will query a list of hostnames then reboot each server. .DESCRIPTION This script will query a list of hostnames then reboot each server. .EXAMPLE Restart-Computer $SERVER .AUTHOR Written by Noel Enrique Alvarez on Friday, April 12, 2019. #>

#The file to be queried for the hostnames
$SERVERS = Get-Content “<<<INSERT PATH>>>”

#Reboot each host in the file
ForEach ($SERVER in $SERVERS)
{Restart-Computer $SERVER -Force}

#End of script


Microsoft Active Directory – Get Computer Object Organizational Unit

You may use the following Windows PowerShell cmdlet to query Microsoft Active Directory (AD) for the hostname and organizational unit (OU) of a computer object.

Get-ADComputer -Filter ‘Name -EQ “HOSTNAME“‘ | Format-List -Property Name, DistinguishedName