Category: Automation

Microsoft Windows PowerShell – Scheduling a Microsoft Windows PowerShell Script

You may use the following settings to configure a Microsoft Windows PowerShell script to run as an automated task in Task Scheduler. This is a very helpful feature for running scripts during the evening.

  • General
    • When running the task, use the following user account: DOMAIN\– USERNAME
    • Run whether user is logged on or not
  • Actions
    • Start a program
    • powershell.exe -file “<<<INSERT PATH TO SCRIPT>>>”
  • Settings
    • Allow task to be run on demand
    • run task as soon as possible after a scheduled start is missed
    • Stop the task if it runs longer than: 3 days
    • If the running task does not end when requested, force it to stop

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

VMware ESXi 5.5 – Scripted Installation

The script below is a sample script that may be used to automate the installation of VMware ESXi 5.5. For more information click here.

#
# Sample scripted installation file
#
# Accept the VMware End User License Agreement
vmaccepteula
# Set the root password for the DCUI and Tech Support Mode
rootpw mypassword
# The install media is in the CD-ROM drive
install –firstdisk –overwritevmfs
# Set the network to DHCP on the first network adapater
network –bootproto=dhcp –device=vmnic0
# A sample post-install script
%post –interpreter=python –ignorefailure=true
import time
stampFile = open(‘/finished.stamp’, mode=’w’)
stampFile.write( time.asctime() )


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 – 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>”


Microsoft Windows PowerShell – List Installed Microsoft Updates

This script will provide a list of the Microsoft updates that have been applied to the local computer and provide the output in a file asd well as a directory of your choice.

Example: Get-HotFix | out-file -filepath “<File Path>”


Microsoft Windows PowerShell – List Microsoft Active Directory Group Members

This script will list the name and account name of each user within an Active Directory group and provide the output of the results in a file and directory of your choice.

Example: Get-ADGroupMember -identity “<Group Name>” | Select Name, SamAccountName | out-file -filepath “<File Path>”


Microsoft Windows PowerShell – Configuring iSCSI Initiator Connections with Windows Server 2012 R2

You may modify the script below to automate the process of configuring an iSCSI Initiator with the Windows Server 2012 R2 operating system.

01