Category: Automation

Microsoft Windows Server 2016 – Delete Recycle Bin Items

You may use the command below from the Microsoft Windows command prompt to delete the objects in the recycle bin for all users on Microsoft Windows Server 2016.

rd /s /q c:\$Recycle.Bin


Amazon Web Services – Bootstrapping – Apache Installation

You may use the following commands to configure an Amazon EC2 instance to install and start the Apache web server upon boot. The commands should be placed in the Advanced Details dialog box during during the provisioning process of an EC2 instance.

#!/bin/bash
sudo su –
yum install -y httpd
systemctl start httpd


Microsoft Windows PowerShell – Get DHCP IPv4 Scope Details

The Windows PowerShell cmdlet below will query a remote Dynamic Host Configuration Protocol (DHCP) server and provide the lease duration of each IPv4 scope.

Get-DhcpServerv4Scope -ComputerName HOSTNAME | Select ScopeID, LeaseDuration


Microsoft Active Directory – Computer Object Password

You may use the following Windows PowerShell cmdlets to view the last time an Active Directory (AD) computer object reset it’s password for all of the computer objects in an AD domain or an individual computer object in an AD domain.

Get-ADComputer -Filter * -Properties PasswordLastSet | Select Name, PasswordLastSet | Sort-Object Name, PasswordLastSet | Format–List
Get-ADComputer -Filter ‘Name -EQ “<<<HOSTNAME>>>”‘ -Properties PasswordLastSet | Select Name, PasswordLastSet | Format-List


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


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