View get_vmhost_lldp_info.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VMware ESXi shell script | |
# Get LLDP info for vmnics (use the get_vmhost_lldp_info_raw function if output is not complete) | |
vmnics="vmnic4 vmnic5" | |
get_vmhost_lldp_info(){ | |
for vmnic in $vmnics; do | |
printf "$vmnic [=]----[=] " | |
pktcap-uw --uplink $vmnic --ethtype 0x88cc -c 1 -o /tmp/vmnic_lldp.pcap > /dev/null | |
hexdump -C /tmp/vmnic_lldp.pcap | awk -F'|' '{printf $2}' | | |
sed -E 's|.+\.([etgETG][teiTEI][a-zA-Z]+ ?-?([0-9]+/)+[0-9]+)(.\.+.{1,2}\.+)+([a-zA-Z][a-zA-Z0-9]+)\..*|\1 (\4)\n|' |
View ping_iscsi.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a list of IP addresses with PowerCLI | |
$Vmhosts = 'sac0esxi*' | |
$Vmks = 'vmk2', 'vmk3', 'vmk5', 'vmk6' | |
Get-VMHostNetworkAdapter -VMHost $Vmhosts -Name $Vmks | sort VMHost, Name | ft -auto VMHost, Name, IP | |
# ESXi host Bash function to ping all iSCSI addresses | |
ping_iscsi () { | |
mtu=8972 | |
failures=0 | |
vmks="vmk2 |
View Disable-VmCbt.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disable CBT on virtual machines | |
$vms = (Get-VM | Get-View).Where{$_.ChangeTrackingEnabled -match 'True'}.Name | |
foreach ($vm in $vms) { | |
$vm_view = Get-vm $vm | get-view | |
$vm_config_spec = New-Object VMware.Vim.VirtualMachineConfigSpec | |
$vm_config_spec.changeTrackingEnabled = $false | |
$vm_view.reconfigVM($vm_config_spec) | |
$snap = New-Snapshot (Get-VM $vm) -Name "Disable CBT" | |
$snap | Remove-Snapshot -confirm:$false |
View Get-VmRdm.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get vSphere RDMs | |
Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName |
View Enable-VmConsoleCopyPaste.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vm = 'vm1', 'vm2' | |
Get-VM $vm | New-AdvancedSetting -name "isolation.tools.paste.disable" -Value $false -Confirm:$false -Force | |
Get-VM $vm | New-AdvancedSetting -name "isolation.tools.copy.disable" -Value $false -Confirm:$false -Force | |
# Power off the VM and back on | |
Stop-VMGuest -VM $vm -Confirm:$false | Out-Null | |
while ((Get-VM -Name $vm).PowerState -ne 'PoweredOff') {Start-Sleep 2} | |
Start-VM -VM $vm -ErrorAction SilentlyContinue |
View 1 Save-EncryptedPassword.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save an encrypted password to a file and retrieve it later for use in a script | |
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File password.txt | |
$user = 'user' | |
$password = Get-Content password.txt | ConvertTo-SecureString | |
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password |
View Copy-FilesToDatastore.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$datastore = Get-Datastore -Name 'ISOs' | Select-Object -First 1 | |
$src = 'C:\Temp\VMware-VCSA-all-6.5.0-8307201.iso' | |
$ds = New-PSDrive -Location $datastore -Name ds -PSProvider VimDatastore -Root '\' | |
Copy-DatastoreItem -Item $src -Destination ds:\ | |
Remove-PSDrive $ds |
View Configure-VCEmailAlerts.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$smtp_sender = 'vcenter@domain.com' | |
$smtp_recipients = 'support@domain.com' | |
$smtp_server = 'smtp.domain.com' | |
$smtp_user = '' | |
$smtp_password = '' | |
$smtp_port = '25' | |
$vcenter = $global:defaultviservers.Name | |
$alarms = @( | |
@{ | |
alarm_definition = 'Datastore usage on disk' |
View Configure-ADAuthentication.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$hosts = '*' | |
$domain = 'domain.local' | |
$ad_group = 'Domain Admins' | |
$user = 'user' | |
$password = 'password' | |
Get-VMHostAuthentication -VMHost $hosts | Set-VMHostAuthentication -JoinDomain -Domain $domain -User $user -Password $password | |
Get-AdvancedSetting -Entity $hosts -Name Config.HostAgent.plugins.hostsvc.esxAdminsGroup | Set-AdvancedSetting -Value $ad_group |
View Create-NimbleDatastore.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vmhost = 'esxi-01.domain.local' | |
$vcenter = 'vcenter.domain.local' | |
$vcenter_user = 'administrator@vsphere.local' | |
# Save encrypted password to a file | |
# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File vcenter-password.txt | |
$vcenter_password = Get-Content vcenter-password.txt | ConvertTo-SecureString | |
$nimble_mgmt_address = '10.1.1.1' | |
$nimble_user = 'admin' | |
# Save encrypted password to a file |
OlderNewer