Files
Zack Meier 1d304511b8 update
2026-04-15 15:45:50 -05:00

136 lines
5.6 KiB
PowerShell

$sctasknum='SCTASK0123474'
$sctask = Get-ServiceNowRecord -Table 'Catalog Task' -ID $sctasknum -IncludeCustomVariable
$request_itemNum = $sctask.request_item.display_value
$TimeStampString = Get-Date -UFormat "%Y%m%d%H%M%S"
$CommentsToAdd=@"
$TimeStampString
Added disk
"@
Update-ServiceNowRecord -ID $sctask.number -Values @{comments = $CommentsToAdd} # enter comments into sctask
Update-ServiceNowRecord -ID $RitmNum -values @{comments = $CommentsToAdd}
If($CloseTask){
Update-ServiceNowRecord -Id $sctask.number -Values @{close_notes = $CommentsToAdd; state = "Closed Complete" }
}
Update-ServiceNowRecord -ID $sctask.number -Values @{short_description = "VMware VM change for $HostName"}
Update-ServiceNowRecord -ID $sctask.number -Values @{assigned_to = "Donald E. Lange"}
Update-ServiceNowRecord -ID $sctask.number -Values @{assigned_to = $assignTo.name}
# full auto cpu/memory
$SCTaskNum = 'SCTASK0123802'
$SCTask = Get-ServiceNowRecord -Table 'Catalog Task' -ID $SCTaskNum
$RitmNum = $SCTask.request_item.display_value
$RITM = Get-ServiceNowRecord -Table 'Requested Item' -ID $RitmNum -IncludeCustomVariable
[string]$HostName = ($RITM.CustomVariable | where-object Name -eq server_name).Value
[int]$CPU = ($RITM.CustomVariable | where-object Name -eq Processors).Value
[int]$MemoryGB = ($RITM.CustomVariable | where-object Name -eq MemoryGB).Value
[int]$Disk1 = ($RITM.CustomVariable | where-object Name -eq disk_1_os).Value
[int]$Disk2 = ($RITM.CustomVariable | where-object Name -eq disk_2_swap_disk).Value
[int]$Disk3 = ($RITM.CustomVariable | where-object Name -eq disk_3).Value
[int]$Disk4 = ($RITM.CustomVariable | where-object Name -eq disk_4).Value
[int]$Disk5 = ($RITM.CustomVariable | where-object Name -eq disk_5).Value
[int]$Disk6 = ($RITM.CustomVariable | where-object Name -eq disk_6).Value
[int]$Disk7 = ($RITM.CustomVariable | where-object Name -eq disk_7).Value
[int]$Disk8 = ($RITM.CustomVariable | where-object Name -eq disk_8).Value
[int]$Disk9 = ($RITM.CustomVariable | where-object Name -eq disk_9).Value
[int]$Disk10 = ($RITM.CustomVariable | where-object Name -eq disk_10).Value
[int]$Disk11 = ($RITM.CustomVariable | where-object Name -eq disk_11).Value
[int]$Disk12 = ($RITM.CustomVariable | where-object Name -eq disk_12).Value
[int]$Disk13 = ($RITM.CustomVariable | where-object Name -eq disk_13).Value
[int]$Disk14 = ($RITM.CustomVariable | where-object Name -eq disk_14).Value
[int]$Disk15 = ($RITM.CustomVariable | where-object Name -eq disk_15).Value
[int]$Disk16 = ($RITM.CustomVariable | where-object Name -eq disk_16).Value
$VM = Get-VM -Name $HostName* | Where-Object { $_.ExtensionData.summary.config.ManagedBy.Type -ne "placeholderVm" }
Write-Warning -Message ("VM: " + $VM.Name)
If($CPU -ne 0){
Write-Verbose -Message ($VM.Name + " attempt increasing CPU to " + $CPU)
try {
$VM | Set-VM -NumCpu $CPU
}
catch {
<#Do this if a terminating exception happens#>
}
}
If($MemoryGB -ne 0){
Write-Verbose -Message ($VM.Name + " attempt increasing MemoryGB to " + $CPU)
try {
$VM | Set-VM -MemoryGB $MemoryGB
}
catch{
}
}
If($Disk1){
$HardDisk = $VM | Get-HardDisk -Name "Hard disk 1"
$Datastore = $HardDisk | Get-Datastore
$HardDiskIncreaseGB = $Disk1 - $HardDisk.CapacityGB
$FreePercentBefore = ($Datastore.FreeSpaceGB) / $Datastore.CapacityGB
$FreePercentAfter = ($Datastore.FreeSpaceGB - $HardDiskIncreaseGB) / $Datastore.CapacityGB
If ($FreePercentAfter -gt 0.10){
Write-Warning -Message ("Hard disk 1: Increasing from " + $HardDisk.CapacityGB + "GB to " + $Disk1 + "GB")
#Write-Warning -Message ("Datastore " + $Datastore.Name + " free space will lower from " + [math]::round($FreePercentBefore,4)*100 + "% to " + [math]::round($FreePercentAfter,4)*100 + "%")
Write-Warning -Message ("Datastore " + $Datastore.Name + " free space will lower from " + [math]::round($FreePercentBefore,4) + " to " + [math]::round($FreePercentAfter,4) + "")
$VM | Get-HardDisk -Name "Hard disk 1" | Set-HardDisk -CapacityGB $Disk1 -Confirm:$false
}
Else{
Write-Error -Message ("Hard disk 1 failed. 20% free space is required for automated disk expansions. " + $Datastore.Name + " would be " + [math]::round($FreePercentAfter,4) + ".")
}
}
If($Disk2){
#$VM | Get-HardDisk -Name "Hard disk 2" | Set-HardDisk -CapacityGB $Disk2
}
If($Disk3){
#$VM | Get-HardDisk -Name "Hard disk 3" | Set-HardDisk -CapacityGB $Disk3
}
<#
If($Disk4){
$VM | Get-HardDisk -Name "Hard disk 4" | Set-HardDisk -CapacityGB $Disk4
}
If($Disk5){
$VM | Get-HardDisk -Name "Hard disk 5" | Set-HardDisk -CapacityGB $Disk5
}
If($Disk6){
$VM | Get-HardDisk -Name "Hard disk 6" | Set-HardDisk -CapacityGB $Disk6
}
If($Disk7){
$VM | Get-HardDisk -Name "Hard disk 7" | Set-HardDisk -CapacityGB $Disk7
}
If($Disk8){
$VM | Get-HardDisk -Name "Hard disk 8" | Set-HardDisk -CapacityGB $Disk8
}
If($Disk9){
$VM | Get-HardDisk -Name "Hard disk 9" | Set-HardDisk -CapacityGB $Disk9
}
If($Disk10){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk10
}
If($Disk11){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk11
}
If($Disk12){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk12
}
If($Disk13){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk13
}
If($Disk14){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk14
}
If($Disk15){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk15
}
If($Disk16){
$VM | Get-HardDisk -Name "Hard disk 10" | Set-HardDisk -CapacityGB $Disk16
}#>