Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Script to automate ESXI deployment

 ################################################

## vSphere ESXi 7.0 Scripted Install - Part 1 ##

################################################

# Accept the VMware End User License Agreement

vmaccepteula


# Set the root password for DCUI

rootpw Passw0rd!!


# Install on the first local disk available on machine

install --firstdisk --overwritevmfs


# Set the network to Static on the first network adapter

network --hostname=esxi7-Auto --device=vmnic0 --bootproto=static --ip=192.168.1.215 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=192.168.1.16


# Reboot

reboot


################################################

## vSphere ESXi 7.0 Scripted Install - Part 2 ##

################################################


# Use busybox interpreter

%firstboot --interpreter=busybox


# Set DNS Suffix

esxcli network ip dns search add --domain=ads.com


# Disable IPv6

esxcli network ip set --ipv6-enabled=false


# Enable SSH

vim-cmd hostsvc/enable_ssh

vim-cmd hostsvc/start_ssh


# Enable NTP

echo "server 0.au.pool.ntp.org" >> /etc/ntp.conf;

echo "server 1.au.pool.ntp.org" >> /etc/ntp.conf;

/sbin/chkconfig ntpd on;


# Create vSwitches

esxcli network vswitch standard add -v vSwitch1

esxcli network vswitch standard add -v vSwitch2


# Set vSwitch MTU's

esxcli network vswitch standard set -v vSwitch1 -m 9000

esxcli network vswitch standard set -v vSwitch2 -m 9000


# Add Additional NIC to vSwitches

esxcli network vswitch standard uplink add --uplink-name=vmnic1 --vswitch-name=vSwitch0

esxcli network vswitch standard uplink add --uplink-name=vmnic2 --vswitch-name=vSwitch1

esxcli network vswitch standard uplink add --uplink-name=vmnic3 --vswitch-name=vSwitch1

esxcli network vswitch standard uplink add --uplink-name=vmnic4 --vswitch-name=vSwitch2

esxcli network vswitch standard uplink add --uplink-name=vmnic5 --vswitch-name=vSwitch2


# Create VMKernel Ports

esxcli network vswitch standard portgroup add --portgroup-name=vMotion --vswitch-name=vSwitch1

esxcli network vswitch standard portgroup add --portgroup-name=NFS --vswitch-name=vSwitch2

esxcli network ip netstack add --netstack=vmotion

esxcli network ip interface add --interface-name=vmk1 --portgroup-name=vMotion --netstack=vmotion --mtu=9000

esxcli network ip interface add --interface-name=vmk2 --portgroup-name=NFS --mtu=9000

esxcli network ip interface ipv4 set --interface-name=vmk1 --ipv4=192.168.10.215 --netmask=255.255.255.0 --type=static

esxcli network ip interface ipv4 set --interface-name=vmk2 --ipv4=192.168.5.215 --netmask=255.255.255.0 --type=static


# Put host in maintenance mode

esxcli system maintenanceMode set -e true


# Reboot to apply settings (disabling IPv6)

esxcli system shutdown reboot -d 15 -r "rebooting after disabling IPv6"

SCOM PowerShell command | Get-SCOMagent , get-scomalert, Get-SCOMManagementPack

 

Cmdlet to list out the agent 

Get-SCOMAgent

 


Get-SCOMAgent | FT -Property displayName, version, ActionAccountIdentity, ProxyingEnabled, HealthState 



Get-SCOMAgent | where {$_.healthstate -eq "success"} |select Name,healthstate, version 



Get-SCOMAgent | where {$_.healthstate -eq "warning"} | select Name,version,healthstate 

 

 

 

 

 

 

Cmdlet to get a list of Management packs


Get-SCOMManagementPack 

 

 

 

 

 

Command to get sealed and unsealed Management pack

 

Get-SCOMManagementPack |where {$_.sealed -eq "true"} |Select name, DisplayName 

 

 

Get-SCOMManagementPack |where {$_.sealed -eq "false"} |Select name, DisplayName 

 

 

 

 

 


Cmdlet to get SCOM alert

Get-SCOMAlert 




Cmdlet to get alert of particular component.


Get-SCOMAlert -Name "*heartbeat*" 

 

 

 

 

 

 

 

Cmdlet to get alert historical alert

Get-SCOMAlert -ComputerName scom | where {$_.severity -eq "error"} | FL

 

 



PowerShell command to list out all the VDAs registered or registered/unregistered to site and schedule it using task scheduler send the report over mail

 PowerShell command to list out all the VDAs registered or registered/unregistered to site and schedule it using task scheduler send the report over mail

The PowerShell command will be used to collect only unregistered VDAs from the site.


Get-BrokerDesktop -MaxRecordCount 5000 | Select-Object ClientName, AssociatedUserFullNames, MachineName, RegistrationState, StartTime, LastDeregistrationReason, CatalogName, LastConnectionTime, FunctionalLevel |Where-object {$_.RegistrationState -eq 'Unregistered'} | Export-Csv -Path C:\TEMP\Get-brokerDesktop.csv |Format-Table –AutoSize

 

Send-MailMessage –From administrator@ads.com –To VDA@ads.com –Subject “Guess what!” -Attachment "Get-brokerDesktop.csv" –Body “I am testing to get VDA status through PowerShell” -SmtpServer smtp.mail.com -Port 25 



Below PowerShell command will be used to collect all VDAs registered/unregistered from the site.


Get-BrokerDesktop -MaxRecordCount 5000 | Select-Object ClientName, AssociatedUserFullNames, MachineName, RegistrationState, StartTime, LastDeregistrationReason, CatalogName, LastConnectionTime, FunctionalLevel, AssociatedUserSID, HostedMachineName | Export-Csv -Path C:\TEMP\Get-broker6.csv |Format-Table -InformationAction Stop -AutoSize

 

Send-MailMessage –From administrator@ads.com –To VDA@ads.com –Subject “Guess what!” -Attachment "Get-brokerDesktop.csv" –Body “I am testing to get VDA status through PowerShell” -SmtpServer smtp.mail.com -Port 25 


If you want  more details, refer below link and update the parameters accordingly.


https://developer-docs.citrix.com/projects/citrix-virtual-apps-desktops-sdk/en/latest/Broker/Get-BrokerMachine/ 


Output will be like below.



You can schedule it using the task scheduler.

You need to save the script file in the same location where the report file is getting exported.

For me it is c:\temp

Login to server from where you want to schedule task

Open Task scheduler

Create new task -> Give task name

In security options select how you want to run the script 

In my case I have selected Run whether user is logged on or not

Check mark on Run with highest privileges.



Click on Triggers and set the scheduled time



Click on Action and in Action select start a program

In program/script browse and select powershell.exe

In arguments: give the script path with script name .ps1

Start in: Give the path where you have kept your script.



Apply OK and wait for the scheduled time, task will execute at scheduled time like below



Get Network adapter details

Below PS command can be use to get physical network and team details.



Get-NetAdapter | Format-table

Get Network Adapter details(Physical Only).
Get-NetAdapter -Physical


Get Network Adapter Statistics

Get-NetAdapterStatistics


List all the available NIC teams.

Get-NetLbfoTeam




Server Uptime and Service Status matching the text command

Some important command to get server uptime and Service status matching the text.

To get server Uptime

================

 Invoke-Command -ScriptBlock {

$dt = Get-Date 

$tz = [System.TimeZone]::CurrentTimeZone

Write-Host "`r`nHostname:" $(hostname)

Write-Host "Timezone:"  $tz.StandardName " / " $tz.DaylightName

Write-Host "Date: " $dt

}

============================
Expected output





===================================================
Get Service status matching the text
===============================

Get-Service | Where-Object {$_.Name -Match "windows" -or $_.DisplayName -Match "window" }

Expected Output


Start a service

Start-Service -Name "ServiceName"

Stop a service

Stop-Service -Name "ServiceName"


PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Stopped  wuauserv           Windows Update


PS C:\Windows\system32> start-service wuauserv
PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Running  wuauserv           Windows Update


PS C:\Windows\system32> stop-service wuauserv
PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Stopped  wuauserv           Windows Update



Windows system up time and high CPU usage processes

 Windows system up time

Invoke-Command -ScriptBlock {
	$ut = (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime 
	$tz = [System.TimeZone]::CurrentTimeZone
	Write-Host "`r`nHostname:" $(hostname)
	Write-Host "Timezone:"  $tz.StandardName " / " $tz.DaylightName
	Write-Host "Up time: " $ut.Days " Days " $ut.Hours " Hours " $ut.Minutes " Minutes `r`n"
}

Sample Output:
Hostname: Computer1
Timezone: Romance Standard Time / Romance Daylight Time
Up time: 4 Days 22 Hours 51 Minutes


Get top 5 high CPU usage processes

Get-Process | Sort CPU -descending | Select -first 5 -Property ID, ProcessName, Description, CPU | Format-List
=================================
Expected output
Id          : 2140
ProcessName : chrome
Description : Google Chrome
CPU         : 681.109375

Id          : 7032
ProcessName : mcshield
Description :
CPU         : 649.71875

Id          : 5016
ProcessName : dptf_helper
Description : Intel(R) Dynamic Tuning Utility Application
CPU         : 516.328125



Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...