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
$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 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 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
## CSV format out to clipboard | |
Get-Snapshot -VM * | select VM,Name,Created,PowerState,Description,@{n='SizeGB';e={'{0:N2}' -f $_.sizegb}} | sort SizeGB | ConvertTo-Csv -NoTypeInformation -Delimiter `t | clip | |
## Out to CSV | |
Get-Snapshot -VM * | select VM,Name,Created,PowerState,Description,@{n='SizeGB';e={'{0:N2}' -f $_.sizegb}} | sort SizeGB | Export-Csv -NoTypeInformation -Path 'VMware Virtual Machine Snapshots.csv' | |
## Out to console | |
Get-Snapshot -VM * | select VM,Name,Created,PowerState,Description,@{n='SizeGB';e={'{0:N2}' -f $_.sizegb}} | sort SizeGB | ft -auto |
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 = '*' | |
$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)" |
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 = '*' | |
$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' |
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
$output = "$($env:TEMP)\iSCSI_Disks.csv" | |
$results = @() | |
$disk = Get-Disk | Where-Object {$_.BusType -eq 'iSCSI'} | Sort-Object -Property Number | |
foreach ($d in $disk) { | |
$partition = Get-Partition -DiskNumber $d.Number | |
$iscsi_session = Get-IscsiSession -Disk $d | |
$obj = New-Object -TypeName PSObject | |
Add-Member -InputObject $obj -MemberType NoteProperty -Name DiskNumber -Value $d.Number |
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
# Host CPU ratio | |
Get-VMHostCpuRatio | Export-Csv -NoTypeInformation 'VMware Host CPU Ratio.csv' | |
# Host datastores | |
Get-VMHostDatastores | Export-Csv -NoTypeInformation 'VMware Host Datastores.csv' | |
# Host CDP/LLDP info | |
Get-VMHostNetworkCdpInfo | Export-Csv -NoTypeInformation 'VMware Host CDP Info.csv' | |
Get-VMHostNetworkLldpInfo | Export-Csv -NoTypeInformation 'VMware Host LLDP Info.csv' |
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 |
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
# 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!" |