update
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
||||
Param(
|
||||
[string]
|
||||
$SCTaskNum
|
||||
)
|
||||
|
||||
New-ServiceNowSession -Url 'northdakota.service-now.com' -Credential $Secret:SNowVMCred
|
||||
Connect-ITDvCenter -Credential $Secret:svcitdvmvcauto
|
||||
|
||||
$Filter = @('assignment_group', '-like', 'NDIT-Server Build Automation'), '-and', @('short_description', '-like', 'Windows Guest OS complete. Hardware team review.'), '-and', @('state', '-eq', '2') # 2 = 'work in progress'
|
||||
$OpenTasks = Get-ServiceNowRecord -Table 'Catalog Task' -Filter $Filter | Sort-Object Number
|
||||
If ($PSBoundParameters.ContainsKey("SCTaskNum")) {
|
||||
Write-Verbose -Message "SCTaskNum parameter found, value is $SCTaskNum"
|
||||
$OpenTasks = $OpenTasks | Where-Object Number -EQ $SCTaskNum
|
||||
}
|
||||
|
||||
Write-Verbose -Message ("OpenTasks found: " + $OpenTasks.count) -Verbose
|
||||
ForEach ($OpenTask in $OpenTasks) {
|
||||
Write-Verbose -Message $OpenTasks.Number -Verbose
|
||||
}
|
||||
|
||||
ForEach ($OpenTask in $OpenTasks) {
|
||||
$Ci = $null
|
||||
$BuildComplete = $null
|
||||
|
||||
# get SCTask, Ritm
|
||||
$SCTaskNum = $OpenTask.number
|
||||
Write-Verbose -Message "Start $SCTasknum" -Verbose
|
||||
$SCTask = Get-ServiceNowRecord -Table 'Catalog Task' -ID $SCTaskNum
|
||||
$shortdescription = $SCTask.short_description
|
||||
$RitmNum = $SCTask.request_item.display_value
|
||||
$Ritm = Get-ServiceNowRecord -Table 'Requested Item' -ID $RitmNum -IncludeCustomVariable -WarningAction SilentlyContinue
|
||||
|
||||
switch (($Ritm.CustomVariable | Where-Object Name -EQ target_platform).Value) {
|
||||
'azure' { $target_platform = "Azure" }
|
||||
'vmware' { $target_platform = "VMware" }
|
||||
}
|
||||
|
||||
$FormFQDN = ($RITM.CustomVariable | Where-Object Name -EQ "host_name").value
|
||||
$FormHostName = $FormFQDN.split('.')[0]
|
||||
|
||||
$Ci = Get-ServiceNowRecord -Table cmdb_ci -Filter @('name', '-eq', $FormHostName)
|
||||
|
||||
If ($Ci) {
|
||||
Write-Verbose -Message ("Ci found, sys_id = " + $Ci.sys_id + ", name = " + $Ci.name + ", fqdn = " + $Ci.fqdn) -Verbose
|
||||
}
|
||||
switch ($target_platform) {
|
||||
{ $_ -like "*VMware*" } {
|
||||
Connect-ITDvCenter -Credential $Secret:svcitdvmvcauto
|
||||
Write-Verbose -Message ("$FormFQDN is a VMware VM. Determine if SRM was requested.") -Verbose
|
||||
$hardware_platform = "VMware";
|
||||
$hardware_type = 'Virtual Machine'
|
||||
|
||||
If ( ($Ritm.CustomVariable | Where-Object Name -EQ 'dr_protection').Value -eq 'No DR') {
|
||||
Write-Verbose -Message ("$FormFQDN dr_protection equals 'No DR'") -Verbose
|
||||
Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum -CloseTask -Verbose
|
||||
}
|
||||
Else {
|
||||
Write-Verbose -Message ("$FormFQDN dr_protection is requested") -Verbose
|
||||
Write-Warning -Message ("SRM is requested, task will not auto close. -- ZM") -Verbose
|
||||
Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum
|
||||
}
|
||||
Disconnect-ITDvCenter
|
||||
}
|
||||
{ $_ -like "*Microsoft Virtual Machine*" } {
|
||||
Write-Verbose -Message ("$FormFQDN is an Azure VM. DR is not an option, proceed.") -Verbose
|
||||
$hardware_platform = "Azure";
|
||||
$hardware_type = 'Virtual Machine'
|
||||
Write-Warning -Message ("Final close task is commented out until testing can occur. -- ZM") -Verbose
|
||||
#Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum
|
||||
}
|
||||
{ $_ -like "*HP*" } {
|
||||
Write-Verbose -Message ("$FormFQDN is an HPE device.") -Verbose
|
||||
$hardware_platform = 'HPE';
|
||||
$hardware_type = 'Physical'
|
||||
Write-Warning -Message ("Final close task is commented out until testing can occur. -- ZM") -Verbose
|
||||
}
|
||||
default {
|
||||
$hardware_platform = 'Other'
|
||||
Write-Warning -Message ("Ci found, but unavailable to determine hardware platform.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Disconnect-ITDvCenter
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
Param(
|
||||
[string]
|
||||
$SCTaskNum
|
||||
)
|
||||
|
||||
New-ServiceNowSession -Url 'northdakota.service-now.com' -Credential $Secret:SNowVMCred
|
||||
Connect-ITDvCenter -Credential $Secret:svcitdvmvcauto
|
||||
|
||||
$Filter = 'active=true^short_descriptionSTARTSWITHAutomated Server Build Task for Windows Machine'
|
||||
$OpenTasks = Get-ITDServiceNowRecord -ItemType 'Catalog Task' -Filter $Filter | Sort-Object Number
|
||||
If ($PSBoundParameters.ContainsKey("SCTaskNum")) {
|
||||
Write-Verbose -Message "SCTaskNum parameter found, value is $SCTaskNum"
|
||||
$OpenTasks = $OpenTasks | Where-Object Number -EQ $SCTaskNum
|
||||
}
|
||||
|
||||
Write-Verbose -Message ("OpenTasks found: " + $OpenTasks.count) -Verbose
|
||||
ForEach ($OpenTask in $OpenTasks) {
|
||||
Write-Verbose -Message $OpenTasks.Number -Verbose
|
||||
}
|
||||
|
||||
ForEach ($OpenTask in $OpenTasks) {
|
||||
$Ci = $null
|
||||
$BuildComplete = $null
|
||||
|
||||
# get SCTask, Ritm
|
||||
$SCTaskNum = $OpenTask.number
|
||||
Write-Verbose -Message "Start $SCTasknum" -Verbose
|
||||
$SCTask = Get-ITDServiceNowRecord -ItemType 'Catalog Task' -Number $SCTaskNum
|
||||
$ShortDescription = $SCTask.short_description
|
||||
#$RitmNum = $SCTask.request_item.display_value
|
||||
$Ritm = Get-ITDServiceNowRecord -ItemType 'Request Item' -SysId ($SCTask.request_item.value) -IncludeVariableSet -WarningAction SilentlyContinue
|
||||
|
||||
switch ( $Ritm.VariableSet.target_platform ) {
|
||||
'azure' { $target_platform = "Azure" }
|
||||
'vmware' { $target_platform = "VMware" }
|
||||
}
|
||||
|
||||
#$FormFQDN = ($RITM.CustomVariable | Where-Object Name -EQ "host_name").value
|
||||
$FormFQDN = ($RITM.VariableSet.host_name)
|
||||
$FormHostName = $FormFQDN.split('.')[0]
|
||||
|
||||
#$Ci = Get-ServiceNowRecord -Table cmdb_ci -Filter @('name', '-eq', $FormHostName)
|
||||
$Ci = Get-ITDServiceNowRecord -Table cmdb_ci -Filter ("name=" + $FormHostName)
|
||||
|
||||
If ($Ci) {
|
||||
Write-Verbose -Message ("Ci found, sys_id = " + $Ci.sys_id + ", name = " + $Ci.name + ", fqdn = " + $Ci.fqdn) -Verbose
|
||||
}
|
||||
Else {
|
||||
switch ($target_platform) {
|
||||
{ $_ -like "*VMware*" } {
|
||||
Connect-ITDvCenter -Credential $Secret:svcitdvmvcauto
|
||||
Write-Verbose -Message ("$FormFQDN is a VMware VM. Determine if SRM was requested.") -Verbose
|
||||
$hardware_platform = "VMware";
|
||||
$hardware_type = 'Virtual Machine'
|
||||
|
||||
If ( ($Ritm.CustomVariable | Where-Object Name -EQ 'dr_protection').Value -eq 'No DR') {
|
||||
Write-Verbose -Message ("$FormFQDN dr_protection equals 'No DR'") -Verbose
|
||||
Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum -CloseTask -Verbose
|
||||
}
|
||||
Else {
|
||||
Write-Verbose -Message ("$FormFQDN dr_protection is requested") -Verbose
|
||||
Write-Warning -Message ("SRM is requested, task will not auto close. -- ZM") -Verbose
|
||||
Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum
|
||||
}
|
||||
Disconnect-ITDvCenter
|
||||
}
|
||||
{ $_ -like "*Microsoft Virtual Machine*" } {
|
||||
Write-Verbose -Message ("$FormFQDN is an Azure VM. DR is not an option, proceed.") -Verbose
|
||||
$hardware_platform = "Azure";
|
||||
$hardware_type = 'Virtual Machine'
|
||||
Write-Warning -Message ("Final close task is commented out until testing can occur. -- ZM") -Verbose
|
||||
#Approve-ITDVMNewBuild -SCTaskNum $SCTaskNum
|
||||
}
|
||||
{ $_ -like "*HP*" } {
|
||||
Write-Verbose -Message ("$FormFQDN is an HPE device.") -Verbose
|
||||
$hardware_platform = 'HPE';
|
||||
$hardware_type = 'Physical'
|
||||
Write-Warning -Message ("Final close task is commented out until testing can occur. -- ZM") -Verbose
|
||||
}
|
||||
default {
|
||||
$hardware_platform = 'Other'
|
||||
Write-Warning -Message ("Ci found, but unavailable to determine hardware platform.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Disconnect-ITDvCenter
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
# if a manually triggered build needs to occur, run this
|
||||
|
||||
Update-Module ITD.Infra-VMware.VirtualMachine
|
||||
New-ITDVMwareWindowsVM -ComputerName $FQDN -CPU $CPU -MemoryGB $MemoryGB -VlanId $VlanId -OS $OS -Environment $Environment -Datacenter $Datacenter -LicensingRestrictions $LicensingRestrictions
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# send JSON payload to AA to create csv file that gets moved to itdwinautop1.nd.gov (and will be built)
|
||||
|
||||
$RestMethodParams = @{
|
||||
Method = 'Post';
|
||||
Uri = 'https://96bdfe01-af80-4575-8f23-e7057184c8f6.webhook.cus.azure-automation.net/webhooks?token=4cWZz%2fq97AqMdlNak6qv2lUurLPFsWmPJmovLmAE%2fNg%3d';
|
||||
Headers = @{ITD = 'mXJU74ABYyDHcVY6iJihPDk8LidJ2ibBA2sA3RAwKaBHS6Gw7Rr2Zz5JZAhPm6wMuvY7X54ZzJxAXaM7ig3PHG4MKvtkBf8X7q3jGNcePgUqg9WCwCSJ3JWG7AA6M39x4vpihKeZV' };
|
||||
Body = [PSCustomObject]@{
|
||||
target_platform = "VMware"
|
||||
target_hostname = 'itdk12cladgwp1.nd.gov';
|
||||
target_cpus = 4;
|
||||
target_memory = 8;
|
||||
target_osdisk = 80;
|
||||
target_datadisk = 9; # this is now swap
|
||||
target_subnet = '10.2.82.208/29';
|
||||
target_os = 'Windows Server 2022 Datacenter';
|
||||
target_environment = 'Production';
|
||||
target_vm_app_name = 'ITD-Edutech-ClassLink';
|
||||
target_datacenter = 'Bismarck';
|
||||
target_licensingrestrictions = 'No Licensing Restrictions';
|
||||
} | ConvertTo-Json;
|
||||
}
|
||||
|
||||
Invoke-RestMethod @RestMethodParams
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
# scheduled task that finds the oldest input file, reads it, and builds a VM with the parameters found
|
||||
|
||||
$TimeStamp = Get-Date -UFormat "%Y%m%d%H%M%S"
|
||||
$TranscriptPath = "F:\AutoBuildLogs\$TimeStamp.log"
|
||||
Start-Transcript $TranscriptPath
|
||||
|
||||
$DriveLetter = 'F'
|
||||
$CsvPath = ($DriveLetter + ":\AutoBuildInputFiles\")
|
||||
$FailedPath = ($DriveLetter + ":\AutoBuildInputFiles\Failed")
|
||||
$CompletedPath = ($DriveLetter + ":\AutoBuildInputFiles\Completed")
|
||||
|
||||
$GetBuildFile = Get-ChildItem -Path $CsvPath -Filter *.csv | Sort-Object LastWriteTime | select -First 1
|
||||
Write-Warning -Message ("Found file " + $GetBuildFile.Name)
|
||||
|
||||
If ($GetBuildFile) {
|
||||
|
||||
$IaasAutoCred = Get-Secret -Name svcitdiaasauto
|
||||
#$IaasAutoCred = $PrvCred
|
||||
|
||||
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -ParticipateInCeip $false -Confirm:$false -InvalidCertificateAction Ignore
|
||||
|
||||
$InputParams = Import-Csv -Path $GetBuildFile.FullName
|
||||
|
||||
$ComputerName = $InputParams.target_hostname.ToLower()
|
||||
Send-MailMessage -From "itdwinauto@nd.gov" -To "vmware@nd.gov" -SmtpServer apprelay1.nd.gov -Body $InputParams -Subject ("AutoBuildFromFile-$ComputerName-" + $InputParams.target_platform)
|
||||
|
||||
try {
|
||||
switch ($InputParams.target_platform) {
|
||||
'azure' {
|
||||
|
||||
}
|
||||
'vmware' {
|
||||
Connect-VIServer -Server itdvmvc1.nd.gov, itdvmvc2.nd.gov -Credential $IaasAutoCred
|
||||
|
||||
New-ITDVMwareWindowsVM -ComputerName $ComputerName `
|
||||
-CPU $InputParams.target_cpus `
|
||||
-MemoryGB $InputParams.target_memory `
|
||||
-DiskOS $InputParams.target_osdisk `
|
||||
-DiskSwap $InputParams.target_datadisk `
|
||||
-Subnet $InputParams.target_subnet `
|
||||
-OS $InputParams.target_os `
|
||||
-Environment $InputParams.target_environment `
|
||||
-Datacenter $InputParams.target_datacenter `
|
||||
-AppName $InputParams.target_vm_app_name `
|
||||
-LicensingRestrictions $InputParams.target_licensingrestrictions `
|
||||
-Credential $IaasAutoCred `
|
||||
-Verbose
|
||||
|
||||
Move-Item -Path $GetBuildFile.FullName -Destination $CompletedPath
|
||||
|
||||
$postParams = [PSCustomObject]@{
|
||||
AutomationName = "Infra-VMware";
|
||||
Action = 'Provisioning';
|
||||
Units = 240;
|
||||
Platform = 'PowerShell-VMware-VMWindows';
|
||||
}
|
||||
|
||||
Invoke-RestMethod -Uri http://itdnettools.nd.gov/services/automation-tracking.py -Method POST -Body ($postParams | ConvertTo-Json)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$error[0]
|
||||
Write-Warning "Email vmware admins about failure"
|
||||
$Body = $error[0] | Select-Object *
|
||||
Send-MailMessage -From autobuild@nd.gov -To "vmware@nd.gov" -Subject "Failure-AutoBuildFromFile-$ComputerName" -SmtpServer apprelay.nd.gov -Body $Body
|
||||
|
||||
Write-Warning "Error detected. Moving csv input file to folder Failed"
|
||||
Move-Item -Path $GetBuildFile.FullName -Destination $FailedPath
|
||||
}
|
||||
Disconnect-VIServer -Server * -Confirm:$false -ErrorAction SilentlyContinue
|
||||
}
|
||||
Else {
|
||||
Stop-Transcript
|
||||
Get-Item -Path $TranscriptPath | Remove-Item
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
# enable upgrade at next reboot
|
||||
$ToolsConfig = New-Object VMware.Vim.VirtualMachineConfigSpec
|
||||
$ToolsConfig.tools = New-Object VMware.Vim.ToolsConfigInfo
|
||||
$ToolsConfig.Tools.ToolsUpgradePolicy = 'upgradeAtPowerCycle'
|
||||
|
||||
# single VM, enable
|
||||
$vm = Get-VM -Name itdscmt1.nd.gov
|
||||
($vm | Get-View).ReconfigVM($ToolsConfig)
|
||||
|
||||
# get all WS
|
||||
$AllVMs = Get-VM | Where-Object { $_.ExtensionData.summary.config.ManagedBy.Type -ne "placeholderVm" }
|
||||
$AllVMsWindows = $AllVMs | Where-Object {$_.Guest.OSFullName -like "*Windows*"}
|
||||
|
||||
$AllVMsDTAP = $AllVMsWindows | Get-TagAssignment -Category DTAP
|
||||
$AllVMsTest = $AllVMsDTAP | Where-Object {$_.Tag.Name -eq 'Test'}
|
||||
$AllVMsProd = $AllVMsDTAP | Where-Object {$_.Tag.Name -eq 'Production'}
|
||||
|
||||
$AllVMsTest | Export-Csv "D:\OneDrive - State of North Dakota\AllTestVMs.csv"
|
||||
$AllVMsProd | Export-Csv "D:\OneDrive - State of North Dakota\AllProdVMs.csv"
|
||||
|
||||
ForEach($VM in $AllVMsTest){
|
||||
($VM | Get-View).ReconfigVM($ToolsConfig)
|
||||
} #### CHECK 2008 non-R2 x3
|
||||
|
||||
# get all Windows and ToolsVersion counts
|
||||
$AllVMGuests = $AllVMs | Get-VMGuest
|
||||
$AllVMGuests | select VMName, ToolsVersion
|
||||
|
||||
# disable upgrade at next reboot
|
||||
$ToolsConfig = New-Object VMware.Vim.VirtualMachineConfigSpec
|
||||
$ToolsConfig.tools = New-Object VMware.Vim.ToolsConfigInfo
|
||||
$ToolsConfig.Tools.ToolsUpgradePolicy = 'manual'
|
||||
|
||||
$vm = Get-VM -Name itdscmt1.nd.gov
|
||||
($vm | Get-View).ReconfigVM($ToolsConfig)
|
||||
|
||||
|
||||
$AllVMs = Get-VM | Where-Object { $_.ExtensionData.summary.config.ManagedBy.Type -ne "placeholderVm" }
|
||||
|
||||
|
||||
|
||||
$AllVMs = Get-VM | Where-Object {$_.Name -like "*itd*" -and $_.Guest.OSFullName -notlike "*Windows*"}
|
||||
|
||||
|
||||
# report
|
||||
$AllVMsWindows | select Name,@{n='OS';e={$_.Guest.OSFullName}},@{n='ToolsVersion';e={($_ | Get-VMGuest).ToolsVersion}},@{n='ToolsPolicy';e={($_ | Get-View).config.tools.toolsupgradepolicy}} -ov ToolsReport | export-csv "D:\vmtools.csv"
|
||||
|
||||
# set prod
|
||||
ForEach($VM in $AllVMsWindows){
|
||||
Write-Warning -Message ($VM.Name)
|
||||
($VM | Get-View).ReconfigVM($ToolsConfig)
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
$ComputerName = @"
|
||||
itddmrdbmssqlu1.nd.gov
|
||||
itddmrdbmssqld1.nd.gov
|
||||
itddmrdbmsu1.nd.gov
|
||||
itddmrdbmsd1.nd.gov
|
||||
"@
|
||||
|
||||
$ComputerName = ConvertTo-Array -MultiLineString $ComputerName
|
||||
|
||||
Invoke-Command -Credential $PrvCred -ComputerName $ComputerName -ScriptBlock {
|
||||
Get-Process -Name ccmexec, cohesity*, nessus*, cortex*, vmware*
|
||||
} | Sort-Object PSComputerName
|
||||
|
||||
<#
|
||||
# Add to Solarwinds
|
||||
$Func = {
|
||||
param($ComputerName)
|
||||
Import-SWDiscovery -ComputerName $ComputerName -Integration ServiceNow
|
||||
}
|
||||
ForEach ($c in $ComputerName) {
|
||||
#Invoke-Command -ComputerName itdslrwnds.nd.gov -ScriptBlock $Func -ArgumentList $c -Credential $IaaSAuto
|
||||
}
|
||||
|
||||
# Validate Solarwinds node creation
|
||||
$Func = {
|
||||
param($ComputerName)
|
||||
$test = Get-SWNode -ComputerName $ComputerName
|
||||
If ($test) { “Pass” }
|
||||
}
|
||||
ForEach ($c in $ComputerName) {
|
||||
|
||||
Invoke-Command -ComputerName itdslrwnds.nd.gov -ScriptBlock $Func -ArgumentList $c -Credential $IaaSAuto
|
||||
}
|
||||
|
||||
Invoke-Command -ComputerName itdsccmp2.nd.gov -ScriptBlock { Get-Process } -Credential $PrvCred
|
||||
#>
|
||||
|
||||
$SCTaskNums = @"
|
||||
SCTASK0173131
|
||||
SCTASK0173136
|
||||
"@
|
||||
|
||||
$SCTaskNums = ConvertTo-Array -MultiLineString $SCTaskNums
|
||||
$SCTaskNums | ForEach-Object { Approve-ITDVMNewBuild -SCTaskNum $_ }
|
||||
|
||||
Reference in New Issue
Block a user