Skip to content

Instantly share code, notes, and snippets.

View Dapacruz's full-sized avatar

David Cruz Dapacruz

View GitHub Profile
@Dapacruz
Dapacruz / Get-IscsiDiskInfo.ps1
Last active September 20, 2018 16:26
Get iSCSI Disk Information
$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
@Dapacruz
Dapacruz / Recover-VM.ps1
Last active July 23, 2018 17:13
Recover Virtual Machine
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
@Dapacruz
Dapacruz / Watch-Device.ps1
Last active July 19, 2018 14:54
Monitor a Device During a Reboot and Receive a Text-to-Speech Notification When it is Back Online
# 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!"
@Dapacruz
Dapacruz / Validate-VMhostNetworking.ps1
Last active July 12, 2018 21:22
Validate VMware vSphere Host Networking
# 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
@Dapacruz
Dapacruz / Generate-VMwareVsphereDocumentation.ps1
Last active August 17, 2018 17:17
Generate VMware vSphere Documentation
# 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'
@Dapacruz
Dapacruz / Get-ComputerIPv4NetworkInfo.ps1
Last active June 20, 2018 15:32
Get Windows Computer IPv4 Network Information
$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}
@Dapacruz
Dapacruz / Remove-Datastores.ps1
Last active June 19, 2018 21:45
Remove VMware vSphere Datastores
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
@Dapacruz
Dapacruz / Ping-VMs.ps1
Last active May 30, 2018 21:56
Ping VMware Virtual Machines on an ESXi Host
$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 }}}}}
@Dapacruz
Dapacruz / Migrate-VMToVDSwitch.ps1
Created May 30, 2018 18:40
Migrate Virtual Machines (VM) to a Virtual Distribututed Switch
$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
@Dapacruz
Dapacruz / Create-NimbleDatastore.ps1
Created May 30, 2018 18:26
Create Nimble Volumes and VMware vSphere Datastores
$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