Created
November 15, 2021 03:57
-
-
Save thegooddoctorgonzo/e00537e165588b68cd635e6243571318 to your computer and use it in GitHub Desktop.
:
This file contains hidden or 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
| $password = Get-Content C:\Scripts\Container\PoshSS.txt | ConvertTo-SecureString -Key (Get-Content C:\Scripts\Container\aes.key) | |
| $VCcreds = New-Object System.Management.Automation.PsCredential("DOMAIN\SVC_ACCT",$password) | |
| if($global:defaultviserver) | |
| { | |
| Disconnect-VIServer -Confirm:$false -ErrorAction Ignore -Server * | |
| } | |
| try{ | |
| Connect-VIServer tincan.DOMAIN -ErrorAction Stop -Credential $VCcreds | |
| } | |
| catch [VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.ViServerConnectionException]{ | |
| Collect-Errors -LogLines $_ -Label "Failed connect to vServer" -Level FATAL -LineNum (Get-CurrentLine) -PassedList ([ref]$NotificationLog) | |
| Write-ToMasterLog -Entries $NotificationLog -Header $Header | |
| exit | |
| } | |
| catch{ | |
| continue | |
| } | |
| Start-Sleep -Seconds 5 | |
| $excludeFolders = "vCLS", "VM Templates", "Master Images" | |
| $vms = Get-vm -Name * -Server tincan* | Where-Object {$_.PowerState -eq "PoweredOn" -and $excludeFolders -notcontains $_.Folder-and $_.Name -notlike "*Assess*"} | |
| $objTemplateObject = New-Object -TypeName psobject | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name Name -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "Hosted Apps/Roles" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "POC Administrator" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "POC Team" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "POC Email" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "System/Cluster" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "System Role" -Value $null | |
| $objTemplateObject | Add-Member -MemberType NoteProperty -Name "Prod/Test/Dev" -Value $null | |
| $objList = New-Object System.Collections.ArrayList | |
| foreach($vm in $vms) | |
| { | |
| $objTemp = $objTemplateObject | select * | |
| $objTemp.Name = $vm.name | |
| $objTemp.'Hosted Apps/Roles' = ($vm | Get-Annotation -CustomAttribute "Hosted Apps/Roles" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'POC Administrator' = ($vm | Get-Annotation -CustomAttribute "POC Administrator" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'POC Team' = ($vm | Get-Annotation -CustomAttribute "POC Team" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'POC Email' = ($vm | Get-Annotation -CustomAttribute "POC Email" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'System/Cluster' = ($vm | Get-Annotation -CustomAttribute "System/Cluster" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'System Role' = ($vm | Get-Annotation -CustomAttribute "System Role" | Select-Object -ExpandProperty value).tostring() | |
| $objTemp.'Prod/Test/Dev' = ($vm | Get-Annotation -CustomAttribute "Prod/Test/Dev" | Select-Object -ExpandProperty value).tostring() | |
| $objList.Add($objTemp) | Out-Null | |
| } | |
| #empty rows | |
| $empty = $objList | Where-Object {$_.'Hosted Apps/Roles' + $_.'POC Administrator' + $_.'POC Team' + $_.'POC Email' + $_.'System/Cluster' + $_.'System Role' + $_.'Prod/Test/Dev' -eq ""} | |
| $body = "The following VMs have no Attributes set in vCenter`r`r`r" | |
| foreach($e in $empty | Sort-Object -Property Name) | |
| { | |
| $body = $body + $e.name.ToString() + "`r" | |
| } | |
| $subject = "VMs With Empty Attributes Report" | |
| $to = "[email protected]","[email protected]" | |
| #$to = "[email protected]" | |
| Send-MailMessage -Body $body -Subject $subject -From "[email protected]" -To $to -SmtpServer "smtpgw.DOMAIN" -Port 25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment