Files
Backup/_NDGOV_WindowsTeam/ITD.Infra-Servers-PowerShellUniversal.Test/ITD-WindowsServer.Lifecycle/New-ITDWindowsVmAzure_Step2.ps1
T
Zack Meier 1d304511b8 update
2026-04-15 15:45:50 -05:00

50 lines
2.3 KiB
PowerShell

[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'FromSCTask')]
$SCTaskNum,
[Parameter(Mandatory = $true, ParameterSetName = 'ManualEntry')]
[string]
$FQDN
)
switch ($PSCmdlet.ParameterSetName) {
'ManualEntry' {
$NewITDWindowsVmAzureParams = @{
FQDN = $FQDN;
}
}
'FromSCTask' {
Write-Verbose -Message ("UAJob.ComputerName = " + $UAJob.ComputerName) -Verbose
switch ($UAJob.ComputerName) {
"ITDWINAUTOT1" { $ServiceNowEnvironment = 'Test' }
"ITDWINAUTOP1" { $ServiceNowEnvironment = 'Production' }
}
Write-Verbose -Message "New-ITDServiceNowSession" -Verbose
New-ITDServiceNowSession -Environment $ServiceNowEnvironment -Credential $Secret:snow_vmcred
$SCTask = Get-ITDServiceNowRecord -ItemType 'Catalog Task' -Number $SCTaskNum
$Ritm = Get-ITDServiceNowRecord -ItemType 'Request Item' -SysId ($SCTask.request_item.value) -IncludeVariableSet -IncludeCustomVariable
$FqdnFromSCTaskDescription = ($SCTask.short_description).display_value.split(' ')[7]
$NewITDWindowsVmAzureParams = @{
FQDN = ( ($Ritm.VariableSet | Where-Object { $_.host_name -eq $FqdnFromSCTaskDescription }).host_name );
AppName = ( (Get-ITDServiceNowRecord -Table cmdb_ci_service_auto -SysId ($Ritm.VariableSet | Where-Object { $_.host_name -eq $FqdnFromSCTaskDescription }).application_info).Name.display_value);
VMEnvironment = ( $Ritm.customvariable.environment.value );
}
}
}
Write-Verbose -Message "Connect to Azure using Service Principal" -Verbose
$tenantId = '2dea0464-da51-4a88-bae2-b3db94bc0c54'
$AppId = '60244573-7130-4026-9c6d-47de73f8ca29'
$SecureStringPwd = $Secret:azure_iaasserviceprincipal
$PSCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AppId, ($SecureStringPwd | ConvertTo-SecureString -AsPlainText -Force)
Connect-AzAccount -ServicePrincipal -Credential $PSCredential -Tenant $tenantId
Write-Verbose -Message "NewITDWindowsVMAzureParams:" -Verbose
Write-Verbose -Message ("FQDN " + $NewITDWindowsVMAzureParams.FQDN) -Verbose
New-ITDWindowsVmAzureStep2 @NewITDWindowsVmAzureParams -Credential $Secret:ndgov_svcitdiaasauto -Verbose