Month: April 2019

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


Hardware – View Architecture of Host

You may use the following command from the command prompt or Windows PowerShell to view the architecture, physical or virtual, of the local or remote host on a network. In the second command substitute the %computername% variable with the hostname of the host to be queried.

systeminfo | findstr /c:”Model:” /c:”Host Name”
systeminfo /s %computername% | findstr /c:”Model:” /c:”Host Name”


Microsoft Active Directory – View a List of Servers

You may use the following Windows PowerShell cmdlet to get a list of all of the Windows Servers in your Microsoft Active Directory (AD) domain. In particular, it will provide the hostname of the server, operating system, and service pack then output the results to a CSV file.

Get-ADComputer -Filter ‘OperatingSystem -like “Windows Server*”‘ -Properties Name, OperatingSystem, OperatingSystemServicePack | Sort-Object -Property Name | Format-List -Property Name, OperatingSystem, OperatingSystemServicePack | Out-File -FilePath “<<>>.csv”