# will use this and make an automated generater and approver #requires -Version 3.0 function Get-CertificateRequestFile { param ( [string]$InitialDirectory = $PSScriptRoot ) [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null $ShowDialog = New-Object System.Windows.Forms.OpenFileDialog $ShowDialog.InitialDirectory = $InitialDirectory $ShowDialog.Filter = "CSR File (*.csr)|*.csr|Request File (*.req)|*.req|Text File (*.txt)|*.txt|All Files (*.*)|*.*" $ShowDialog.ShowDialog() | Out-Null return $ShowDialog.FileName } function Get-CertificateTemplates { $script:IssuingCA = certutil -config - -ping $script:IssuingCA = $script:IssuingCA | Where-Object { ($_ -match '\\') -and ($_ -notmatch 'Connecting')} $TemplateList = certutil -CATemplates -config $script:IssuingCA return $TemplateList } $script:IssuingCA = "" $TemplateItems = @{} $i = 0 $RequestFile = Get-CertificateRequestFile $Templates = Get-CertificateTemplates foreach ($Template in $Templates) { if ($Template.Contains("--")) { $CurrentItem = $Template -split ' -- ' $TemplateItems.Add($i,$CurrentItem[0]) $i++ } } do { Clear-Host Write-Output "`n" Write-Output "Selected Certificate Authority: $script:IssuingCA`n" $TemplateItems.GetEnumerator() | Sort-Object Name | ForEach-Object {Write-Output (" {0} - {1}" -F $_.Key, $_.Value)} $SelectedItem = Read-Host -Prompt "`nSelect the number for the requested template (CTRL+C to quit)" if ($SelectedItem -notin @(0..$i)) { $CurrentUIColor = $Host.UI.RawUI.ForegroundColor $Host.UI.RawUI.ForegroundColor = 'Yellow' Write-Output "Please select a valid number or CTRL+C to quit.." $Host.UI.RawUI.ForegroundColor = $CurrentUIColor Start-Sleep -Seconds 2 } } while ($SelectedItem -notin @(0..$i)) $results = $TemplateItems.GetEnumerator() | Where-Object { $_.Key -eq $SelectedItem} $SelectedTemplate = ($($results.Value -split ':')[0]).Trim() certreq -submit -config $script:IssuingCA -attrib "CertificateTemplate:$SelectedTemplate" $RequestFile Clear-Variable TemplateItems