This file contains hidden or 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 hidden or 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 |
This file contains hidden or 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 hidden or 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
| $services = Import-Csv -Path Services.csv | |
| $fname = "Report-$(get-date -f yyyyMMdd.HHmmss).json" | |
| $report = @() | |
| # Export services to JSON for readability | |
| ConvertTo-Json -InputObject $services | Out-File -FilePath Services.json -Force -Confirm:$false | |
| foreach ($svc in $services) { | |
| foreach ($addr in $svc.Destination_Address.split(',')) { | |
| $obj = New-Object -TypeName PSObject |
This file contains hidden or 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
| $params = @{ | |
| To = 'user@domain.com' | |
| From = 'test@client.com' | |
| Subject = 'Test Alert' | |
| Body = ' ' | |
| SmtpServer = 'smtp-relay.gmail.com' | |
| UseSsl = $true | |
| } | |
| Send-MailMessage @params |
This file contains hidden or 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' |
This file contains hidden or 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 |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 }}}}} |