# It all starts with a single line of powershell code.
"I ran at: " + (get-date)
$ENV:USERNAME

Write-Verbose -Verbose "Import Modules"
#Remove-Module ITD.Infra-Certificate-External.JsonDB
Import-Module ITD.Infra-Certificate-External.JsonDB 
Import-Module ITD.Infra-Certificate-External.General -DisableNameChecking

Write-Verbose -Verbose "Setting Database Environment"
Set-JDEnvironment -Name Prod



Write-Verbose -Verbose "Collect certs up for Renewal"
$certs=Get-ICE-CertUpforRenewal

Write-Verbose -Verbose "Proccessing Certs"
foreach ($cert in $certs) {

  "Processing: " + $cert.CommonName
  Write-Host $cert.CommonName
  Write-Host $cert.ParameterSetName 

  if ($cert.ParameterSetName -eq "Cloud Service") {
    $AppParams = @{
      CommonName = $cert.CommonName
      SubjectAlternative = $cert.SubjectAlternative
      ApplicationName = $cert.ApplicationName
    }
    }
  elseif ($cert.ParameterSetName -eq "Windows") {
    $AppParams = @{
      CommonName = $cert.CommonName
      SubjectAlternative = $cert.SubjectAlternative
      DestinationServer = $cert.DestinationServer
      PfxtoPasswordState =  ([System.Convert]::ToBoolean($cert.PfxtoPasswordState))
     }
  }
  else {
       "Param set not defined: " + $cert.CommonName
    }

# Define the script you want to run
$ScriptName = "Infra-Certificate-External.Sectigo/New-SectigoPfxCertificate.ps1"

# Invoke the script and store the job object

   $Job = Invoke-PSUScript -Name $ScriptName -Integrated -Parameters $AppParams 
}
#exit

$job







