Skip to content

Instantly share code, notes, and snippets.

View DavoudTeimouri's full-sized avatar

Teimouri DavoudTeimouri

View GitHub Profile
@DavoudTeimouri
DavoudTeimouri / VMCPU_RDY_Alarm_PowerCLI.ps1
Created May 31, 2019 10:27
Virtual Machine CPU RDY Alarm
#====================================================================#
# SCRIPT: CPU_Ready_Alarm.ps1 #
# FUNCTION: Detect, analyaze CPU ready alarms and migrate #
# problomatic VMs to another host #
# CREATED: 30/01/2015 #
# MODIFIED: 10/08/2015 #
# OWNER: Davoud Teimoru / Teimouri.net #
# VERSION: v.1.1 #
#====================================================================#
# CHANGELOG: #
@DavoudTeimouri
DavoudTeimouri / VeeamBR_IPRule_Linux.sh
Created May 27, 2019 06:49
Veeam Backup & Replication - Re-IP Rule on Linux VM - Example 2
#!/bin/bash
# The script will be worked on RHEL/Fedora/CentOS.
# Set logging options
# Variables.
primary_gw="192.168.100.254"
replica_gw="192.168.200.254"
primary_ipaddr="192.168.100.0"
replica_ipaddr="192.168.200.10"
primary_netmask="24"
replica_netmask="24"
@DavoudTeimouri
DavoudTeimouri / VeeamBR_IPRule_Linux.sh
Last active May 27, 2019 06:50
Veeam Backup & Replication - Re-IP Rule on Linux VM - Example 1
#!/bin/bash
# The script will be worked on RHEL/Fedora/CentOS.
# Set logging options
# Variables.
primary_gw="192.168.100.254"
replica_gw="192.168.200.254"
primary_ipaddr="192.168.100.10"
replica_ipaddr="192.168.200.10"
@DavoudTeimouri
DavoudTeimouri / ChangeLocalAccountPassESXi_PowerCLI.ps1
Created May 27, 2019 05:58
Change Local Account Password on ESXi
Function ConvertFrom-SecureToPlain {
param( [Parameter(Mandatory=$true)][System.Security.SecureString] $SecurePassword)
# Create a "password pointer"
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
# Get the plain text version of the password
$PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
@DavoudTeimouri
DavoudTeimouri / CheckTimeSyncVM_PowerCLI.ps1
Created May 27, 2019 05:51
Check Time Synchronization with Host on Virtual Machines
#####################################################################################################
##Script: Get-VMToolsTimeSync ##
##Description: Get VMware Tools Time Synce Status ##
##Created by: Davoud Teimouri ##
##Creation Date: March 27, 2018 ##
#####################################################################################################
#Create output table
$TableName="TimeSync"
$Table = New-Object system.Data.DataTable “$TableName”
@DavoudTeimouri
DavoudTeimouri / iLO_NTPConfiguration_PowerShell.ps1
Created May 27, 2019 05:23
Configure NTP on iLO via HPE Scripting Tools for Windows PowerShell
$Servers="iLO1 IP","iLO2 IP","iLO..N IP"
$Credential=Get-Credential
ForEach ($Server in $Servers)
{
Set-HPiLOIPv6NetworkSetting -Server $Server -Credential $Credential -DHCPv6SNTPSetting N -DisableCertificateAuthentication
Set-HPiLONetworkSetting -Server $Server -Credential $Credential -Timezone "Etc/UTC" -SNTPServer1 "NTP Server Address" -DHCPSNTP N -DisableCertificateAuthentication
}
@DavoudTeimouri
DavoudTeimouri / Invoke-VMScript_Example.ps1
Created May 27, 2019 05:19
Invoke-VMScript Challenges with Linux Guest
$Script=@'
rm -rf /customizing.sh
touch /customizing.sh
echo "#!/bin/bash" >> /customizing.sh
echo "sed -i '1d' /etc/resolv.conf" >> /customizing.sh
echo "sed -i '3d' /etc/hosts" >> /customizing.sh
echo "sed -i '12d' /etc/sysconfig/network-scripts/ifcfg-eth0" >> /customizing.sh
echo "sed -i '13d' /etc/sysconfig/network-scripts/ifcfg-eth0" >> /customizing.sh
echo "sed -i '14d' /etc/sysconfig/network-scripts/ifcfg-eth0" >> /customizing.sh
echo "sed -i '15d' /etc/sysconfig/network-scripts/ifcfg-eth0" >> /customizing.sh
@DavoudTeimouri
DavoudTeimouri / AddLocalAdminESXi_PowerCLI.ps1
Created May 26, 2019 16:38
Add Local Administrator Account on ESXi
#Connect to ESXi hosts via root account
$VMHosts="ESXi1 IP/DNS Name","ESXi2 IP/DNS Name",....,"ESXiN IP/DNS Name"
$Accounts="User1","User2",....,"UserN"
Foreach ($VMHost In $VMHosts)
{
Connect-VIServer -Protocol https -Server $VMHost -User root -Password QWERTY
Foreach ($Account In $Accounts)
{
#Create User with Shell Access
Write-Host "Create User For $Account"
@DavoudTeimouri
DavoudTeimouri / ChangeLinuxIP_PowerCLI.ps1
Last active May 26, 2019 16:34
[How To]: Change Linux IP Address via PowerCLI
#Get Guest OS Credential
$Credential=Get-Credential
#Get VM Names (As Name Template) - Example Test-2*
$VM=Read-Host "Please Enter The VMs Template Name"
#Get IP Address Range - Example 10.1.1 or 192.168 - This IP Range Will Be Used For Replacing
$NIPAddress=Read-Host "Please Enter New IP Range"
$OIPAddress=Read-Host "Please Enter Current IP Range"
#Replace New IP Range With Old IP Range
Get-VM "$VM" | Invoke-VMScript -ScriptText 'sed -ri "s|$NIPAddress|$OIPAddress|" /etc/sysconfig/network-scripts/ifcfg-eth0 && cat /etc/sysconfig/network-scripts/ifcfg-eth0' -GuestCredential $credential
Get-VM "$VM" | Invoke-VMScript -ScriptText 'sed -ri "s|$NIPAddress|$OIPAddress|" /etc/fstab && cat /etc/fstab' -GuestCredential $credential