sync
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
$Filter = '&$select=ID,Title,DateCreated,Status,DataCenter,Environment,StartupPriority,OS,Processors,RAM,DiskTotal,DataProtection,DR_Protection,SRM_RecoveryVMtype,LicensingRestrictions,Network/Vlan_Id,Network/CIDR,AppName/Title,Cluster/Name&$expand=Network/Id,AppName/Id,Cluster/Id'
|
||||
$URLVMItems = "https://share.nd.gov/itd/computer-systems/distributed-systems/vmware/_api/lists/getbytitle('VM Guests')/items?" + '$top=10000' + $Filter
|
||||
$InvokeRestMethodParams = @{
|
||||
Uri = $URLVMItems;
|
||||
Method = "Get";
|
||||
headers = @{ "Accept" = "application/json;odata=verbose" };
|
||||
UseBasicParsing = $true;
|
||||
}
|
||||
$z = (Invoke-RestMethod @InvokeRestMethodParams -UseDefaultCredentials) -creplace '"Id":', '"Idx":' | ConvertFrom-Json
|
||||
$VMList = $z.d.results
|
||||
|
||||
$URLAppNames = "https://share.nd.gov/itd/computer-systems/distributed-systems/vmware/_api/lists/getbytitle('VM App Name')/items?" + '$top=10000'
|
||||
$InvokeRestMethodParams = @{
|
||||
Uri = $URLAppNames;
|
||||
Method = "Get";
|
||||
headers = @{ "Accept" = "application/json;odata=verbose" };
|
||||
UseBasicParsing = $true;
|
||||
}
|
||||
$z = (Invoke-RestMethod @InvokeRestMethodParams -UseDefaultCredentials) -creplace '"Id":', '"Idx":' | ConvertFrom-Json
|
||||
$AppNameList = $z.d.results
|
||||
|
||||
$AllAppNameVMs = $AppNameList | where-object Cohesity -eq "All VMs"
|
||||
$NewAppNameVMs = $AppNameList | where-object Cohesity -eq "New VMs Only"
|
||||
|
||||
|
||||
# compare new vm list to cohesity vm list
|
||||
$NewVMs = $VMList | where-object DateCreated -gt (Get-Date -Year 2021 -Month 2 -Day 1)
|
||||
|
||||
$CohesityVMs = Get-CohesityVMwareVM -Protected
|
||||
|
||||
$compare = Compare-Object -ReferenceObject $NewVMs.Title -DifferenceObject $CohesityVMs.Name
|
||||
$VMsToAdd = $compare | where-object Sideindicator -eq "<="
|
||||
$VMsToAddAppNames = $VMsToAdd.InputObject | forEach-object { ($VMList | where-object Title -eq $_).AppName.Title } | Select-Object -unique
|
||||
|
||||
$AllProtectionGroups = Get-CohesityProtectionJob
|
||||
|
||||
$AllProtectionSourceObject = Get-CohesityProtectionSourceObject
|
||||
$AppNamesToReview = [System.Collections.ArrayList]@()
|
||||
ForEach ($AppName in $VMsToAddAppNames) {
|
||||
$SourceObjects = $AllProtectionSourceObject | Where-Object Name -eq $AppName
|
||||
$ExistingPGs = Get-CohesityProtectionJob -Names $AppName
|
||||
|
||||
If ($ExistingPGs) {
|
||||
$PGsWithTags = $ExistingPGs | where-object { $_.vmTagIds -match '8744' -or $_.vmTagIds -match '8747' }
|
||||
If ($PGsWithTags) { $Style = "Tagged VMs" }
|
||||
Else { $Style = "All VMs" }
|
||||
|
||||
$obj = [PSCustomObject]@{
|
||||
AppName = $AppName;
|
||||
Style = $Style
|
||||
}
|
||||
}
|
||||
Else {
|
||||
$obj = [PSCustomObject]@{
|
||||
AppName = $AppName;
|
||||
Style = "New PG, needs human"
|
||||
}
|
||||
}
|
||||
$null = $AppNamesToReview.Add($obj)
|
||||
}
|
||||
|
||||
$AppNamesToReview | sort-object AppName
|
||||
|
||||
ForEach ($item in $VMsToAdd) {
|
||||
$SPItem = $null
|
||||
|
||||
# get appname, then appname metadata
|
||||
$VMSPItem = $VMList | where-object Title -eq $item.InputObject
|
||||
$AppName = $VMSPItem.AppName.Title
|
||||
$AppNameSPItem = $AppNameList | where-object Title -eq $AppName
|
||||
|
||||
|
||||
ForEach ($SourceObject in $SourceObjects) {
|
||||
switch ($AppNameSPItem.Cohesity) {
|
||||
$null {
|
||||
If ($AppNameSPItem.Created -gt (Get-Date -Year 2021 -Month 2 -Day 1)) {
|
||||
# created after 2021-02-01, set "All VMs"
|
||||
$AppNameProtection = "All VMs"
|
||||
}
|
||||
Else {
|
||||
# created before 2021-02-01, set "New VMs"
|
||||
$AppNameProtection = "New VMs Only"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# find if protection group exists
|
||||
$CohesityPGs = Get-CohesityProtectionJob -Names $AppName
|
||||
If ($CohesityPGs) {
|
||||
|
||||
}
|
||||
Else {
|
||||
New-ITDCohesityProtectionGroupWIP -AppName $AppName
|
||||
switch ($AppNameProtection) {
|
||||
'All VMs' {
|
||||
# do nothing
|
||||
}
|
||||
'New VMs Only' {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
# create protection group if needed, configure for "All VMs" condition, end
|
||||
# if protection group exists, find out if protect all VMs, or just new
|
||||
# if all VMs, no work to do
|
||||
# if new VMs, add VM to protection group
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
# Cohesity Protection Groups with the entire AppName protected
|
||||
Get-CohesityProtectionJob | Where-Object { $_.vmTagIds -notmatch 8747 -and $_.vmTagIds -notmatch 8744 } | sort-object Name
|
||||
|
||||
# Cohesity Protection Groups with only new AppName VMs protected
|
||||
Get-CohesityProtectionJob | Where-Object { $_.vmTagIds -match 8747 -or $_.vmTagIds -match 8744 } | sort-object Name
|
||||
Reference in New Issue
Block a user