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' | |
$virtual_machines = Get-VM -Location $vmhost | |
$vcenter = 'vcenter.domain.local' | |
$vcenter_user = 'administrator@vsphere.local' | |
# 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 | |
$vcenter_password = Get-Content 'Distributed Switch Migration\password.txt' | ConvertTo-SecureString | |
if(-not $global:DefaultVIServers) { | |
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $vcenter_user, $vcenter_password |
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_names = 'SQL2', 'APP2' | |
$orig_vcenter = 'vc01.client.local' | |
$new_vcenter = 'vcenter.client.local' | |
foreach ($vm_name in $vm_names) { | |
$vm = Get-VM -Server $orig_vcenter -Name $vm_name | |
$vm_path = $vm.extensiondata.config.files.vmpathname | |
'Shutting down {0} ...' -f $vm.Name | |
Stop-VMGuest -Server $orig_vcenter -VM $vm -Confirm:$false | Out-Null |
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
$ignore = '' | |
Write-Host; Get-VMHost * | | |
Get-VM | ? { $_.PowerState -match 'on' } | | |
Select-Object -Property Name, @{n='IPAddr'; e={$_.Guest.IPAddress}} | | |
% { foreach ($ip in $_.ipaddr) { $vm_name = $_.name; $vm_ip = $ip; if ($ip -match '^\d{1,3}\.' -and $ip -notin $ignore) { ping -n 1 $ip | | |
% { if (Select-String -InputObject $_ -SimpleMatch 'Request timed out') { '{0} ({1})' -f $vm_name, $vm_ip; Select-String -InputObject $_ -SimpleMatch "Pinging|Reply|Request"; Write-Host }}}}} |
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
break | |
$eql_group_addr = '1.1.1.1' | |
$eql_user = 'grpadmin' | |
$vcenter_addr = 'vcenter.domain.loc' | |
$vcenter_user = 'administrator@vsphere.local' | |
$vmhosts = '*' | |
$creds = Get-Credential -UserName $vcenter_user -Message 'Enter Password' | |
Connect-VIServer -Server $vcenter_addr -Credential $creds |
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
$hostname = 'localhost' | |
Get-WmiObject -ComputerName $hostname -Class win32_networkadapterconfiguration | | |
select PSComputerName, Description, MacAddress, @{n='IPAddress'; e={$_.IPAddress -match "(\d{1,3}\.){3}\d{1,3}"}}, DHCPEnabled, @{n='DefaultIPGateway'; e={$_.DefaultIPGateway -match "(\d{1,3}\.){3}\d{1,3}"}}, DNSDomain, ServiceName | | |
? {$_.MacAddress -and $_.IPAddress} | |
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
# Test ESXi Host Networking | |
$vmhosts = 'test_esxi-01.domain.net', 'test_esxi-02.domain.net' | |
$mgmt_vmks = 'vmk0' | |
$mgmt_addrs = Get-VMHostNetworkAdapter -VMHost $vmhosts -Name $mgmt_vmks | select -ExpandProperty IP | |
$vmotion_vmks = 'vmk2', 'vmk3' | |
$vmotion_addrs = Get-VMHostNetworkAdapter -VMHost $vmhosts -Name $vmotion_vmks | select -ExpandProperty IP |
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
$subnets = @( | |
'10.1.1.253/22' | |
'10.10.10.252/24' | |
'10.1.20.253/24' | |
'10.120.10.252/22' | |
'10.220.10.252/22' | |
'10.254.254.253/24' | |
'10.100.1.249/22' | |
'10.200.1.249/22' | |
'10.30.1.251/22' |
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
# Monitor a device during a reboot and receive an text-to-speech notification when it is back online | |
# Requires PowerShell Community Extensions (Install-Module -Name PSCX) | |
$ip_address = '8.8.4.4' | |
while (-not (Test-Connection -ComputerName $ip_address -Quiet -Count 1)) {sleep 5}; Out-Speech "Host $ip_address is back online!" |
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 PowerCLI | |
# Virtual machine (VM) inventory report | |
$properties = @( | |
'Name' | |
@{n='HostName';e={$_.ExtensionData.Guest.HostName}} | |
@{n='IpAddress';e={$_.Guest.IpAddress.where{$_ -match '(\d{1,3}\.){3}\d{1,3}'} -join ', '}} | |
@{n='GuestFullName';e={$_.ExtensionData.Guest.GuestFullName}} | |
@{n='ToolsVersion';e={$_.Guest.ToolsVersion}} | |
@{n='ToolsBuild';e={$_.Guest.VM.ExtensionData.Guest.ToolsVersion}} | |
@{n='ToolsStatus';e={$_.Guest.VM.ExtensionData.Guest.ToolsStatus}} |
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
break | |
$vmhost = '*' | |
$vcenter = 'vcenter.domain.local' | |
$vcenter_user = 'administrator@vsphere.local' | |
$guest_creds = Get-Credential 'administrator' | |
# Save an encrypted password to a file and retrieve it later for use in a script | |
# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File vc_password.txt | |
$vcenter_password = Get-Content 'vc_password.txt' | ConvertTo-SecureString |