404 lines
21 KiB
PowerShell
404 lines
21 KiB
PowerShell
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#vCenter Credentials
|
|
$creds = Get-Credential
|
|
Connect-VIServer itdvmvc1.nd.gov, itdvmvc2.nd.gov -Credential $creds
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#ConvertTo-Array
|
|
$VMs=@"
|
|
itdtaxtga1.nd.gov
|
|
itdtaxpfa1.nd.gov
|
|
itdtaxsga1.nd.gov
|
|
itdtaxsga2.nd.gov
|
|
itdtaxpga1.nd.gov
|
|
itdtaxpga2.nd.gov
|
|
itdtaxpga3.nd.gov
|
|
"@
|
|
$VMs=ConvertTo-Array -MultiLineString $VMs
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Move VM to Datastore
|
|
$VMdatastore = 'VMWINDOWS1_143_A9K_R_SHRDPPLSFTST'
|
|
Get-VM $VMs | Get-HardDisk
|
|
Get-VM $VMs | Move-VM -DiskStorageFormat Thin -Datastore $VMdatastore
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Copy Files to/from Remote Computer
|
|
#$fileloc = "C:\Users\delange\State of North Dakota\-Tm-ITD-Virtualization - Documents\VMware\Upgrades\ESXi\6.5.0Update3preGen9\VMware-ESXi-6.5.0-Update3-13932383-HPE-preGen9-650.U3.9.6.8.8-Jun2019.iso"
|
|
$fileloc = "C:\users\delange\Downloads\sql.zip"
|
|
#$fileloc = "O:\Backups\vp_grandforks\vp_grandforks.bak"
|
|
#$fileloc = "C:\temp3\AccelaSchool\*"
|
|
#$fileloc = "C:\temp\vp_bis_11252019.bak"
|
|
#$fileloc = "C:\ITD\vc-itdvmvc1.nd.gov-2020-01-14--19.33-53492.tgz"
|
|
#$fileloc = "D:\Upgrades\VMware\VMware-VCSA-all-6.5.0-14836121.iso"
|
|
#$fileloc = "F:\Support Bundles\vc-itdvmvc1.nd.gov-2020-01-07--19.02-29010.tgz"
|
|
#$destination = "D:\Upgrades\VMware\"
|
|
#$destination = "D:\delange"
|
|
#$destination = "C:\users\delange\Downloads\"
|
|
#$destination = "C:\inetpub\wwwroot\"
|
|
$destination = "D:\ITD\temp\"
|
|
#$servers = 'itdvmutil'
|
|
$servers = 'itdps-update.nd.gov'
|
|
#$servers = 'itdps-images.nd.gov'
|
|
#Copy to server
|
|
foreach ($server in $servers){
|
|
$s=New-PSSession $server -Credential $creds
|
|
Copy-Item $fileloc -ToSession $s -Destination $destination
|
|
}
|
|
#Copy from server
|
|
foreach ($server in $servers){
|
|
$s=New-PSSession $server -Credential $creds
|
|
Copy-Item $fileloc -FromSession $s -Destination $destination
|
|
}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Approve New VMs
|
|
Compare-ITDVMwareVMtoSharePoint -NewBuilds -OutVariable MatchSP | Format-Table
|
|
$MatchSP -Match $false | Sort-Object Name | Format-Table
|
|
$VMs=@"
|
|
itdohrcdbp1.nd.gov
|
|
itdohrcwebp1.nd.gov
|
|
"@
|
|
$VMs=ConvertTo-Array -MultiLineString $VMs
|
|
Approve-ITDVMwareVMNewBuild -ComputerName $VMs
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Snapshots/Clones
|
|
#Get Current Snapshots
|
|
Get-VM | Get-Snapshot | Select-Object Name,VM | Sort-Object -Property Name | Format-Table -AutoSize #| clip.exe
|
|
#Take Snapshot
|
|
$SnapId = 2151..2156
|
|
New-ITDVMwareVMSnapshotTask -id $SnapId -vCenterCredential $creds
|
|
#Delete Snapshot from Scripted Task
|
|
$SnapId = 2186
|
|
Remove-ITDVMwareVMSnapshot -Id $SnapId -vCenterCredential $creds
|
|
#Delete Snapshot taken manually
|
|
$VM = 'bnd0704.nd.gov','itdscmt1.nd.gov'
|
|
Get-VM -Name $VM | Where-Object -Property PowerState -EQ PoweredOn | Get-Snapshot | Remove-Snapshot -Confirm:$false
|
|
#New Clone
|
|
$CloneId = 2149
|
|
New-ITDVMwareVMCloneTask -Id $CloneId -vCenterCredential $creds
|
|
#Delete Clone
|
|
$CloneId = 2117
|
|
Get-VM | Where-Object -Property Name -Like "*$CloneId*"
|
|
foreach ($Clone in $CloneId){
|
|
$DeleteClone = Get-VM | Where-Object -Property Name -Like "*$Clone*"
|
|
$DeleteClone | Remove-VM -DeleteFromDisk -Confirm:$false
|
|
}
|
|
#Snap entire vCenter environment at once
|
|
Get-VM itdvmpsc1*,itdvmvc1*,itdvmpsc2*,itdvmvc2* | New-Snapshot -Name "Converge External PSC"
|
|
Get-VM itdvmpsct1*,itdvmvct1*,itdvmpsct2*,itdvmvct2* | New-Snapshot -Name "PSCT2 Decommissioned"
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Edit VMs
|
|
#Add CPU
|
|
$VMs = 'itdsql16p1.nd.gov'
|
|
$cpu = '4'
|
|
Get-VM $VMs
|
|
Set-VM $VMs -NumCpu $cpu -Confirm:$false
|
|
#Remove CPU
|
|
$VMs = 'bnd0557.nd.gov'
|
|
$cpu = '1'
|
|
Get-VM -Name $VMs | Shutdown-VMGuest -Confirm:$false
|
|
#Start-Sleep -Seconds 60
|
|
Get-VM -Name $VMs
|
|
Get-VM -Name $VMs | Set-VM -NumCPU $cpu -Confirm:$false
|
|
Start-VM $VMs -Confirm:$false
|
|
#Increase RAM
|
|
$VMs = 'itdcndhf16qps.nd.gov','itdcndhefqps.nd.gov'
|
|
$ram = '12'
|
|
Get-VM $VMs
|
|
Set-VM $VMs -MemoryGB $ram -Confirm:$false
|
|
#Remove RAM
|
|
$VMs = ''
|
|
$ram = ''
|
|
Get-VM $VMs | Shutdown-VMGuest -Confirm:$false
|
|
Start-Sleep -Seconds 60
|
|
Get-VM -Name $VMs | Set-VM -MemoryGB 16 -Confirm:$false
|
|
Start-VM $VMs -Confirm:$false
|
|
#Disconnect CDROM
|
|
$VMs = 'itdcndstrwt7.nd.gov'
|
|
foreach ($VM in $VMs){
|
|
Get-VM $VM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false
|
|
}
|
|
#Expand Disks
|
|
$VM = 'itdcndstvm04.nd.gov'
|
|
Get-VM | Where-Object -Property Name -Like "*$VM*"
|
|
Get-VM $VM | Get-HardDisk | Select-Object Name,CapacityGB,Filename
|
|
$harddisk = "Hard Disk 2"
|
|
$increasedisk = 3
|
|
$datastore = Get-VM $VM | Get-HardDisk | Where-Object -Property Name -EQ $harddisk | Get-Datastore
|
|
Get-Datastore $datastore | Select Name,FreeSpaceGB,CapacityGB
|
|
$newcap = (Get-VM $VM | Get-HardDisk | Where-Object -Property Name -EQ $harddisk).CapacityGB + $increasedisk
|
|
$newcap
|
|
Get-VM $VM | Get-HardDisk | Where-Object -Property Name -EQ $harddisk | Set-HardDisk -CapacityGB $newcap -Confirm:$false
|
|
#List NumCpu, MemoryGB, Total HardDiskSizeGB
|
|
$VMs = 'itd1xaes2','itdbiscmsvr','itdredskyaes','itdwfoaes4'
|
|
$datacenter = 'Primary Datacenter'
|
|
$harddisk = @{n="HardDiskSizeGB";e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}
|
|
foreach ($VM in $VMs){
|
|
Get-Datacenter $datacenter | Get-VM | Where-Object -Property Name -Like "$VM*" | Select-Object -Property Name,NumCpu,MemoryGB,$harddisk
|
|
}
|
|
foreach ($VM in $VMs){
|
|
Get-VM | Where-Object -Property Name -Like "$VM*" | Get-HardDisk | Select-Object Name,CapacityGB,Filename | Sort-Object Filename -Descending
|
|
}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Port groups
|
|
#New distributed port group
|
|
$IP = '10.2.160.240/28' <#10.10.10.10/28#>
|
|
$VLANid = '3326' <#0001#>
|
|
New-ITDVMNetwork -CIDR $IP -VLAN $VLANid
|
|
#Remove distributed port group
|
|
$portgroup = 'dvPG_'
|
|
Get-VDPortgroup | Where-Object -Property Name -EQ $portgroup | Remove-VDPortGroup -Confirm:$false
|
|
#Manually add port group
|
|
$BismarckVDSwitch = 'dvSwitch3-PDC-AVAYA1-Data'
|
|
$MandanVDSwitch = 'dvSwitch3-SDC-AVAYA2-Data'
|
|
$PGName = 'dvPG3_2278_165.234.164.0_27'
|
|
$VlanId = '2278'
|
|
Get-VDSwitch -Name $BismarckVDSwitch | New-VDPortGroup -Name $PGName -NumPorts 1 -VlanId $VlanId
|
|
Get-VDSwitch -Name $BismarckVDSwitch | Get-VDPortGroup | Where-Object {$_.Name -like ("*" + "_" + $VlanId)} | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -FailoverDetectionPolicy BeaconProbing
|
|
Get-VDSwitch -Name $BismarckVDSwitch | Get-VDPortGroup | Where-Object {$_.Name -like ("*" + "_" + $VlanId)} | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -BlockOverrideAllowed $false -ResetPortConfigAtDisconnect $false
|
|
Get-VDSwitch -Name $MandanVDSwitch | New-VDPortGroup -Name $PGName -NumPorts 1 -VLANID $VlanId
|
|
Get-VDSwitch -Name $MandanVDSwitch | Get-VDPortGroup | Where-Object {$_.Name -like ("*" + "_" + $VlanId)} | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -FailoverDetectionPolicy BeaconProbing
|
|
Get-VDSwitch -Name $MandanVDSwitch | Get-VDPortGroup | Where-Object {$_.Name -like ("*" + "_" + $VlanId)} | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -BlockOverrideAllowed $false -ResetPortConfigAtDisconnect $false
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Delete VMs
|
|
#Rename VMs for decommission
|
|
$VMs=@"
|
|
itdcndstfwp.nd.gov
|
|
itdcndstfsowp.nd.gov
|
|
itdcndstfwp1.nd.gov
|
|
itdcndstfapp1.nd.gov
|
|
itdcndstfwp2.nd.gov
|
|
itdcndstfapp2.nd.gov
|
|
"@
|
|
$VMs=ConvertTo-Array -MultiLineString $VMs
|
|
Remove-ITDVMWareVM -ComputerName $VMs | Select-Object -Property Name,PowerState
|
|
foreach ($VM in $VMs){
|
|
Get-VM | Where-Object -Property Name -Like "$VM*" | Select-Object -Property Name,PowerState
|
|
}
|
|
#Delete VM - FINAL DELETE
|
|
$deleteVM = foreach ($VM in $VMs){
|
|
Get-VM | Where-Object -Property Name -Like "$VM*delete*"
|
|
}
|
|
$deleteVM.Name
|
|
$deleteVM | Remove-VM -DeleteFromDisk -Confirm:$false
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Replace VMs
|
|
$VMs = 'itdexchcasbis2.nd.gov','itdexchcasman2.nd.gov','itdcndhehb.nd.gov','itdcndheclnadd.nd.gov'
|
|
foreach ($VM in $VMs){
|
|
$VMold = Get-VM | Where-Object -Property Name -Like "$VM*" | Where-Object -Property PowerState -EQ PoweredOff
|
|
$VMnew = Get-VM | Where-Object -Property Name -Like "$VM*new*"
|
|
$VMtags = ($VMold | Get-TagAssignment).Tag | Sort-Object -Unique
|
|
foreach ($VMtag in $VMtags){
|
|
New-TagAssignment -Entity $VMnew -Tag $VMtag
|
|
}
|
|
Remove-ITDVMWareVM -ComputerName $VMold.Name
|
|
Set-VM -VM $VMnew -Name $VMold -Confirm:$false
|
|
}
|
|
foreach ($VM in $VMs){
|
|
Get-VM | Where-Object -Property Name -Like "$VM*" | Get-TagAssignment
|
|
}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Datastores
|
|
$Datastore = 'VMWINDOWS1_138_A9K_R_BNDFISERV'
|
|
#Rescan Host Cluster
|
|
Get-Cluster WINDOWS1 | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs
|
|
#Maintenance Mode
|
|
$Datastore = 'VMPS1_48_A9K_R','VMPS1_49_A9K_R','VMPS1_50_A9K_R','VMPS1_51_A9K_R','VMPS1_52_A9K_R','VMPS1_53_A9K_R'
|
|
Get-Datastore $Datastore | Set-Datastore -MaintenanceMode $true -EvacuateAutomatically
|
|
Get-Datastore $Datastore | Set-Datastore -MaintenanceMode $false
|
|
#Adding Datastores
|
|
$VMhost = 'itdbisvm-sql01.nd.gov'
|
|
#Get CanonicalName
|
|
Get-ScsiLun -VmHost $VMhost -LunType Disk | Select-Object CanonicalName,CapacityGB | Sort-Object CanonicalName
|
|
#Create Datastore
|
|
$Datastore = 'VMSQL1_119_A9K_TAX'
|
|
$CanonicalName = 'naa.6001738ccce06785000000000018ef24'
|
|
New-Datastore -VMHost $VMhost -Name $Datastore -Path $CanonicalName -VMFS -FileSystemVersion 6
|
|
#Removing Datastores
|
|
#Datastore Unmap
|
|
$Datastores = 'VMLINUX1_248_V5K_SECLOG','VMLINUX1_249_V5K_SECLOG','VMLINUX1_250_V5K_SECLOG','VMLINUX1_251_V5K_SECLOG'
|
|
#$Datastores = (Get-DatastoreCluster SQL1_A9K_General | Get-Datastore).Name
|
|
foreach ($Datastore in $Datastores){
|
|
Start-ITDVMwareDatastoreUnmap -Datastore $Datastores
|
|
}
|
|
#Expand Datastore
|
|
$Datastore = Get-Datastore 'VMTEL1_124_A9K_VBRICK'
|
|
$esxi = Get-View -Id ($Datastore.ExtensionData.Host | Select-Object -Last 1 | Select-Object -ExpandProperty Key)
|
|
$DatastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem
|
|
$ExpandOptions = $DatastoreSystem.QueryVmfsDatastoreExpandOptions($Datastore.ExtensionData.MoRef)
|
|
$DatastoreSystem.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef,$expandOptions.spec)
|
|
#Disable Storage I/O Control
|
|
$Datastores = 'VMWINDOWS1_90_A9K','VMWINDOWS1_91_A9K','VMWINDOWS1_92_A9K','VMSQL1_57_A9K','VMLINUX1_99_A9K_ELASTIC'
|
|
foreach ($Datastore in $Datastores){
|
|
Get-Datastore $Datastore | Set-Datastore -StorageIOControlEnabled $false
|
|
}
|
|
#Unmount/Detach
|
|
#Unmount/Detach
|
|
Remove-ITDVmwareDatastoreStep1 -LunId 90
|
|
#Step2 Storage Admin unmaps LUN from Host
|
|
#LUN cleanup (after storage unmap, should return empty)
|
|
Remove-ITDVMwareDatastoreStep3 -LunId 57
|
|
Remove-ITDVMwareDatastoreStep3 -LunId 90
|
|
Remove-ITDVMwareDatastoreStep3 -LunId 91
|
|
Remove-ITDVMwareDatastoreStep3 -LunId 92
|
|
Remove-ITDVMwareDatastoreStep3 -LunId 99
|
|
|
|
$Id = "_90_"
|
|
$Datastores = Get-Datastore | Where-Object Name -Like ("*_" + $Id + "_*")
|
|
ForEach ($Datastore in $Datastores) {
|
|
$SharePointRecord = $null
|
|
|
|
$DatastoreHosts = $Datastore | Get-VMHost
|
|
$VMHostCanonicalName = (Get-ScsiLun -VmHost ($DatastoreHosts | Select -First 1) | where-object RuntimeName -Like "*$Id*").CanonicalName
|
|
$SharePointRecord = ($SharePointList | Where-Object Title -eq $Datastore.Name)
|
|
|
|
If ($SharePointRecord.ExtentName -eq $VMHostCanonicalName) {
|
|
Write-Verbose ($Datastore.Name + " *** " + $VMHostCanonicalName + " *** CanonicalName accurate in SharePoint, continuing with unmount")
|
|
|
|
try {
|
|
Get-Datastore $Datastore #| Unmount-Datastore
|
|
$DatastoreHosts | Select-Object -First 1 | Remove-Datastore $Datastore -Confirm:$false -RunASync
|
|
$DatastoreRemovalSuccess += $Datastore.Name
|
|
}
|
|
catch {
|
|
$DatastoreRemovalFailure += $Datastore.Name
|
|
}
|
|
}
|
|
else {
|
|
Write-Error ($Datastore.Name + " *** " + " *** CanonicalName mismatch with SharePoint Record")
|
|
}
|
|
}
|
|
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Clusters
|
|
#Get cluster that VM resides in
|
|
foreach ($VM in $VMs){
|
|
Get-VM $VM | Get-Datastore | Select-Object Name
|
|
}
|
|
#Get VMs with Resource Reservations
|
|
$Cluster = 'TEL1'
|
|
$VMs = Get-Cluster $Cluster | Get-VM
|
|
$VMs2 = Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -or $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation -ne "0"}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Tags
|
|
$VMs=@"
|
|
itdintrpmgrp1.nd.gov
|
|
"@
|
|
$VMs=ConvertTo-Array -MultiLineString $VMs
|
|
#Spectrum Protect for VE
|
|
$TagCat = "Backup Management (IBM Spectrum Protect)"
|
|
$TagName = "Included"
|
|
#RPO
|
|
$TagCat = "VR RPO"
|
|
$TagName = "ABR"
|
|
$TagName = "RPO 0:15"
|
|
$TagName = "RPO 0:30"
|
|
$TagName = "RPO 1:00"
|
|
$TagName = "RPO 2:00"
|
|
$TagName = "RPO 4:00"
|
|
$TagName = "RPO 8:00"
|
|
#VR Datastores
|
|
$TagCat = "VR Datastores"
|
|
$TagName = "VMAVAYA2_210_A9K_VR"
|
|
$TagName = "VMLINUX2_212_A9K_VR"
|
|
$TagName = "VMLINUX2_213_A9K_VR"
|
|
$TagName = "VMSQL2_218_A9K_VR"
|
|
$TagName = "VMTEL2_220_A9K_VR"
|
|
$TagName = "VMTEL2_221_A9K_VR"
|
|
$TagName = "VMWAS2_222_A9K_VR"
|
|
$TagName = "VMWAS2_223_A9K_VR"
|
|
$TagName = "VMWINDOWS2_224_A9K_VR"
|
|
$TagName = "VMWINDOWS2_225_A9K_VR"
|
|
$TagName = "VMWINDOWS2_226_A9K_VR"
|
|
#SRM Type
|
|
$TagCat = "SRM Type"
|
|
$TagName = "SRM Reserved"
|
|
$TagName = "SRM Repurposed Suspend"
|
|
$TagName = "SRM Repurposed"
|
|
#HA Host
|
|
$TagCat = "HA"
|
|
$TagName = "Dedicated HA Host"
|
|
#Assign Tag
|
|
foreach ($VM in $VMs){
|
|
$VM = Get-VM $VM | Where-Object -Property PowerState -EQ PoweredOn
|
|
$VIServer = $VM.Uid.split('@')[1].split(':')[0]
|
|
New-TagAssignment -Entity $VM -Tag (Get-Tag -Server $VIServer -Category $TagCat -Name $TagName) -Server $VIServer
|
|
}
|
|
foreach ($VMHost in $VMHosts){
|
|
$VMHost = Get-VMHost $VMHost
|
|
$VIServer = $VMHost.Uid.split('@')[1].split(':')[0]
|
|
New-TagAssignment -Entity $VMHost -Tag (Get-Tag -Server $VIServer -Category $TagCat -Name $TagName) -Server $VIServer
|
|
}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#VMhosts
|
|
$VMhosts=@"
|
|
itdbisvm-av01.nd.gov
|
|
itdbisvm-av02.nd.gov
|
|
itdbisvm-av03.nd.gov
|
|
itdbisvm-av04.nd.gov
|
|
itdbisvm-av05.nd.gov
|
|
"@
|
|
$VMhosts=ConvertTo-Array -MultiLineString $VMhosts
|
|
#VMhosts by Cluster
|
|
$VMhosts = (Get-Cluster | Where-Object -Property Name -EQ WINDOWS1 | Get-VMHost | Sort-Object).Name
|
|
#Disable Lockdown Mode
|
|
foreach ($VMhost in $VMhosts){
|
|
(Get-VMHost $VMhost | Get-View).ExitLockdownMode()
|
|
}
|
|
#Enable Lockdown Mode
|
|
(Get-VMHost $VMhost | Get-View).EnterLockdownMode()
|
|
$VMhosts = Get-Datacenter | Where-Object -Property Uid -Like "*itdvmvc*" | Get-VMHost
|
|
(Get-VMHost $Vmhosts | Get-View).EnterLockdownMode()
|
|
foreach ($VMhost in $VMhosts){
|
|
(Get-VMHost $VMhost | Get-View).EnterLockdownMode()
|
|
}
|
|
#Enable SSH services
|
|
Get-VMHost $VMhost | Get-VMHostService | Where-Object {$_.Label -eq "SSH"} | Start-VMHostService
|
|
Get-VMHost $VMhost | Get-VMHostService | Where-Object {$_.Label -eq "ESXi Shell"} | Start-VMHostService
|
|
#Get Lockdown Status for all VMhosts
|
|
$VMhosts = Get-Datacenter | Where-Object -Property Uid -Like "*itdvmvc*" | Get-VMHost
|
|
$Lockdown = @{N="Lockdown";E={$_.Extensiondata.Config.adminDisabled}}
|
|
Get-VMHost $VMhosts | Select-Object Name,$Lockdown
|
|
#Disable Alarms
|
|
foreach ($VMhost in $VMhosts){
|
|
$disableHost = Get-VMhost $VMhost
|
|
$viServer = $disableHost.Uid.Split('@')[1].Split(':')[0]
|
|
$alarmMgr = Get-View AlarmManager -Server $viServer
|
|
$alarmEnabled = $disableHost.ExtensionData.AlarmActionsEnabled
|
|
if ($alarmEnabled -eq $true){
|
|
$alarmMgr.EnableAlarmActions($disableHost.ExtensionData.MoRef,$false)
|
|
}
|
|
$disableHost = $null
|
|
}
|
|
#Enable Alarms
|
|
foreach ($VMhost in $VMhosts){
|
|
$enableHost = Get-VMhost $VMhost
|
|
$viServer = $enableHost.Uid.Split('@')[1].Split(':')[0]
|
|
$alarmMgr = Get-View AlarmManager -Server $viServer
|
|
$alarmEnabled = $enableHost.ExtensionData.AlarmActionsEnabled
|
|
if ($alarmEnabled -eq $false){
|
|
$alarmMgr.EnableAlarmActions($enableHost.ExtensionData.MoRef,$true)
|
|
}
|
|
$enableHost = $null
|
|
}
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#Disk Space
|
|
$VMs=@"
|
|
itdcndhhpdb.nd.gov
|
|
itdcndhhpdbdr.nd.gov
|
|
itdcndhfpdb.nd.gov
|
|
itdcndhfpdbdr.nd.gov
|
|
"@
|
|
$VMs=ConvertTo-Array -MultiLineString $VMs
|
|
$export = 'C:\temp\usedspace.csv'
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable Avaya1 | Export-Csv $export
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable Avaya1 | Export-Csv $export -Append
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable Linux1 | Export-Csv $export -Append
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable ODM1 | Export-Csv $export -Append
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable PS1 | Export-Csv $export -Append
|
|
Get-VM $VMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable WAS1 | Export-Csv $export -Append
|
|
Get-VM $WindowsVMs | Select-Object Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable Windows1 | Export-Csv $export -Append
|
|
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$export = "C:\temp2\usedspace.csv"
|
|
Export-Csv -Path $export -InputObject $Avaya1
|
|
|
|
|
|
Get-VM $VMs | Select-Object @{n="Cluster"; e={($_ | Get-Cluster).Name}},Name,@{n="UsedSpaceGB"; e={[math]::round($_.UsedSpaceGB )}},@{n="ProvisionedSpaceGB"; e={[math]::round($_.ProvisionedSpaceGB )}} -OutVariable Avaya1 | Export-Csv $export |