$VMHostNames=@('itdvmnrmsec01.nd.gov')

# New-ITDServiceNowChangeRequest
$VMHostNames | ForEach-Object {
    $NewITDServiceNowChangeRequestParams = @{
        #TemplateName              = 'NDIT-SPS-Server Add/Chg/Del'
        RequestedByUsername       = 'zmeier';
        Category                  = 'Systems Platforms - Systems';
        Subcategory               = 'VMware';
        Impact                    = 3;
        ShortDescription          = "Firmware and software updates for $_";
        Description               = "Following HPE VMware firmware/software recipe for 2024.04.01: HPE ProLiant Firmware Update and VMware upgrade to v7.0 U3p.  The entire process will take 6-8 hours per server.  http://vibsdepot.hpe.com/customimages/Valid-vLCM-Combos.pdf";
        Justification             = "Required for continued support";
        Implementation            = "install";
        RiskImpactAnalysis        = "Low - VMware hosts running on the HPE ProLiant platforms will be shutdown.  All active virtual machine workloads will be migrated to other hosts in their respective clusters during the maintenance.  No outage expected.";
        BackoutPlan               = "n/a"
        TestPlan                  = "n/a"
        WhoIsImpacted             = "n/a";
        StartTime                 = (Get-Date)
        EndTime                   = (Get-Date).AddHours(8);
        AssignmentGroup           = 'NDIT-Computer Systems Windows';
        ChangeManagerUsername     = 'khellman';
        ChangeCoordinatorUsername = 'gpgolberg';
        AssignedToUsername        = 'zmeier';
    }

    $CHG = New-ITDServiceNowChangeRequest @NewITDServiceNowChangeRequestParams
}
# To-do list
# Confirm-ITDServiceNowChangeRequest

$CHGNums = @"
CHG0143889
CHG0143888
CHG0143887
CHG0143886
CHG0143885
CHG0143884
CHG0143883
"@

$CHGNums = ConvertTo-Array -MultiLineString $CHGNums

$CHGNums | ForEach-Object {
    Complete-ITDServiceNowChangeRequest -Number $_ -CloseCode "Successful" -CloseNotes "Firmware and software installed." #$CHG.Number.value
}



# use standard CHG template NDIT-SPS-Server Add/Chg/Del
<# ps lifecycle verbs
    submit         --- new
    approve / deny --- skip if std chg
    schedule       --- ???
    implement      --- ???
    confirm        --- implement and review
    complete       --- close
#>
# date/time testing
Update-ITDServiceNowRecord -ItemType 'Change Request' -Number CHG0098995 -Values @{
    start_date = (Get-Date -Year 2023 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0 -AsUTC).ToString('yyyy-MM-dd HH:mm:ss');
    end_date   = (Get-Date -AsUTC).AddMinutes(1).ToString('yyyy-MM-dd HH:mm:ss')
}



# New-ITDServiceNowServiceCatalogRequest
$NewITDServiceNowServiceCatalogRequest = @{
    CategoryItemName  = "Application Server";
    RequestedForEmail = 'zmeier@nd.gov';
    Values            = @{
        request_type                 = "";
        application_name             = "";
        environment                  = "";
        require_hosting_quote        = 'No';
        server_name                  = '';
        add_change_disaster_recovery = 'No';
        additional_comments          = "";
    };
}

New-ITDServiceNowServiceCatalogRequest @NewITDServiceNowServiceCatalogRequest




# New Server Build Request x1
# server name
$ServerName = 'itdzmtest559.nd.gov'

# Subnet lookup
$Subnet = '10.11.12.0/23' ### review these lookup fields\
$cidr_block = Get-ITDServiceNowRecord -Table 'cmdb_ci_ip_network' -Filter "name=$Subnet"

# Agency lookup
$AgencyPrefix = "ITD"
switch ($AgencyPrefix) {
    'ITD' { $AgencyNum = '112.0' }
}
$Agency = Get-ITDServiceNowRecord -Table 'cmn_department' -Filter "id=$AgencyNum"

# team lead lookup
$team_lead = Get-ITDServiceNowUser -Email 'gpgolberg@nd.gov'

# AppName lookup
$AppName = "Infra-VMware"
$application_info = Get-ITDServiceNowRecord -Table cmdb_ci_service -Filter ("name=$AppName")




