Skip to content

Instantly share code, notes, and snippets.

View Dapacruz's full-sized avatar

David Cruz Dapacruz

View GitHub Profile
@Dapacruz
Dapacruz / Configure-ADAuthentication.ps1
Created May 30, 2018 18:05
Configure Active Directory Authentication on VMware ESXi Hosts
$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
@Dapacruz
Dapacruz / Configure-VCEmailAlerts.ps1
Last active May 30, 2018 16:50
Set Up VMware vCenter Email Alerts
$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'
@Dapacruz
Dapacruz / Send-MailMessage.ps1
Last active November 26, 2018 17:03
Send Email From PowerShell
$params = @{
To = 'user@domain.com'
From = 'test@client.com'
Subject = 'Test Alert'
Body = ' '
SmtpServer = 'smtp-relay.gmail.com'
UseSsl = $true
}
Send-MailMessage @params
@Dapacruz
Dapacruz / 1_Test-FirewallServicesOutside.ps1
Last active December 8, 2018 21:05
Firewall Migration Validation
$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
@Dapacruz
Dapacruz / Nmap-Ping-Sweep.ps1
Last active July 12, 2018 21:29
Nmap Ping Sweep of Multiple Subnets
$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'
@Dapacruz
Dapacruz / Get-VmRdm.ps1
Created February 2, 2018 23:27
Get VMware vSphere RDMs
# Get vSphere RDMs
Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName
@Dapacruz
Dapacruz / Move-VmsToNewVcenter.ps1
Last active May 30, 2018 18:42
Move virtual machines from one VMware vCenter to another
$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
@Dapacruz
Dapacruz / Copy-FilesToDatastore.ps1
Last active May 22, 2018 18:11
Copy Files to a VMware vSphere Datastore from PowerCLI
$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
@Dapacruz
Dapacruz / Redirect-VMHostLogs.ps1
Last active October 16, 2018 21:29
Redirect VMware ESXi Host Logs
$hosts = '*'
$datastore_name = 'NS-VMFS-01'
$datastore = Get-Datastore -Name $datastore_name | Select-Object -First 1
$log_dir = '[{0}] Logs' -f $datastore.Name
$scratch_location = '{0}/Logs' -f $datastore.ExtensionData.Info.Url -replace 'ds://'
foreach ($h in (Get-VMHost $hosts | Sort-Object -Property Name)) {
Write-Host "$($h.Name): Redirecting log files ..."
$result = Get-AdvancedSetting -Entity $h -Name Syslog.global.logDir | Set-AdvancedSetting -Value "$log_dir/$h" -Confirm:$false
Write-Host "New syslog location: $($result.Value)"
@Dapacruz
Dapacruz / Configure-Ntp.ps1
Created December 7, 2017 00:02
Configure/Enable NTP on a VMware ESXi Host
$hosts = '*'
$ntp_servers = '10.10.1.10', '10.10.1.5'
Get-VMHostService -VMHost $hosts | Where-Object {$_.key -eq 'ntpd'}
Get-VMHostNtpServer -VMHost $hosts
Add-VMHostNtpServer -VMHost $hosts -NtpServer $ntp_servers
Get-VMHostService -VMHost $hosts | Where-Object {$_.key -eq 'ntpd'} | Start-VMHostService | Set-VMHostService -Policy 'automatic'