Authentication Powershell到windows server 2012 PKI的身份验证

Authentication Powershell到windows server 2012 PKI的身份验证,authentication,windows-server-2012,pki,Authentication,Windows Server 2012,Pki,我在powershell中编写了一个脚本,从.INF文件生成.REQ。然后必须将该文件(即.REQ)导入PKI,PKI随后生成.CERT 我的问题是,我不知道如何从Powershell向PKI进行身份验证。第二个问题,如果我可能会问,我如何选择证书模板(在PKI在线屏幕中,我有一个选择框,在其中我选择我的模板(例如Wifi客户端”) 这是到目前为止我的代码,当然我不知道如何进行身份验证,这是我在这里的主要问题。我知道登录名和密码(我使用RDP成功连接自己) #生成请求文件.req 写入主机“此脚

我在powershell中编写了一个脚本,从.INF文件生成.REQ。然后必须将该文件(即.REQ)导入PKI,PKI随后生成.CERT

我的问题是,我不知道如何从Powershell向PKI进行身份验证。第二个问题,如果我可能会问,我如何选择证书模板(在PKI在线屏幕中,我有一个选择框,在其中我选择我的模板(例如Wifi客户端”)

这是到目前为止我的代码,当然我不知道如何进行身份验证,这是我在这里的主要问题。我知道登录名和密码(我使用RDP成功连接自己)

#生成请求文件.req
写入主机“此脚本生成一个.REQ(证书创建中的步骤1/3)”
写入主机“”
写入主机“步骤1/3:创建带有密钥长度和其他参数的.INF文件,创建一个.REQ文件”
写入主机“步骤2/3:将.REQ文件导入中间PKI并生成.CER”
写入主机“步骤3/3:从.CER文件中,使用可导出密钥创建一个.PFX”
#变量声明
#
#UID=编号为PDA或系列编号
#$Login=Login sur la PKI intermediate
#$Pass=密码在PKI中间层上
$Date=(获取日期).ToString('ddMMyyyy')
写入主机“”
[string]$UID=read host“请输入设备名称(或序列号)”
$Path=“C:\users\youcef\Desktop\Julie\”
$Login=“我”
$Pass=“Pass”
#INF文件内容
$ReqFile=“$UID”+”“+”$Date“+”.req”
$InfFile=@”
[NewRequest]`r
Subject=“CN=$UID”`r
KeySpec=1
可导出=真
RequestType=PKCS10
[保单声明扩展]
策略=内部策略
[内部政策]
OID=1.2.3.4.1455.67.89.5
通知=“法律政策声明
[证书服务器]
RenewalKeyLength=1024
RenewalValidityPeriod=年
RenewalValidityPeriodUnits=2
CRL周期=周
CRLPeriodUnits=52
CRLDeltaPeriod=天
CRLDeltaPeriodUnits=0
LoadDefaultTemplates=1
AlternateSignatureAlgorithm=0
"@
#从INF文件生成请求文件
写入主机“生成证书请求文件…”-ForegroundColor黄色;
$MYCERTNAME=“$UID”+“\u”+“$Date”+”.inf”
新项$MYCERTNAME-类型文件-值$InfFile
certreq-新的$path\$MYCERTNAME$path\$ReqFile
写入主机“”
写入主机“成功生成$UID的证书请求文件!”-foregroundcolor DarkGreen;
#PKI认证:我完全迷路了
连接认证机构-ComputerName ca01.company.com
$password=converttosecurestring“password”-AsPlainText-Force
$cred=新对象-typename System.Management.Automation.PSCredential`
-argumentlist$Login$Pass
$serverNameOrIp=“192.168.1.1”
重新启动计算机-计算机名$serverNameOrIp`
-身份验证默认值`
-凭证$cred
$cred=新对象-typename System.Management.Automation.PSCredential`
-参数列表$username,$password
$serverNameOrIp=”https://pki.mycompany.fr/certsrv/certrqxt.asp"
重新启动计算机-计算机名$serverNameOrIp`
-身份验证默认值`
-凭证$cred
certreq-提交-配置“https://pki.mycompany.fr/certsrv/certrqxt.asp“$path\$ReqFile$path\$UID.cer
#certreq-提交-配置“https://pki.mycompany.fr\certsrv“$path\$ReqFile$path\$UID.cer
certreq-接受$path\$UID.cer
certutil-exportpfx-p“Welcome123”MY$UID$path\clientcerts\$UID.pfx

我解决了直接在服务器上启动脚本的问题。 不是最好的解决方案,但我设法在Powershell中使用远程会话

# Generate Request File .req

Write-Host " This script generates a .REQ (step 1/3 in certificate creation)"
Write-Host " "
Write-Host " Step 1/3: create .INF file with Key length and other parameters, create a .REQ file"
Write-Host " Step 2/3: import the .REQ file into the Intermediate PKI and generate a .CER"
Write-Host " Step 3/3: from the .CER file, create a .PFX with the exportable key"


# Variables declaration
#
#  UID = nom du PDA ou son numero de serie
#  $Login = login sur la PKI intermediate
#  $Pass = Password sur la PKI intermediate

$Date = (Get-Date).ToString('ddMMyyyy')
Write-Host " "
[string]$UID = read-host "Please enter the Device Name (or Serial Number)"
$Path = "C:\users\youcef\Desktop\Julie\"

$Login = "me"
$Pass = "pass"



# INF File content 

$ReqFile = "$UID" + "_" + "$Date" + ".req"
$InfFile = @"
[NewRequest]`r
Subject = "CN=$UID"`r
KeySpec = 1
Exportable = TRUE
RequestType = PKCS10
[PolicyStatementExtension]
Policies=InternalPolicy
[InternalPolicy]
OID= 1.2.3.4.1455.67.89.5
Notice="Legal Policy Statement
[Certsrv_Server]
RenewalKeyLength=1024
RenewalValidityPeriod=Years
RenewalValidityPeriodUnits=2
CRLPeriod=weeks
CRLPeriodUnits=52
CRLDeltaPeriod=Days
CRLDeltaPeriodUnits=0
LoadDefaultTemplates=1
AlternateSignatureAlgorithm=0
"@


# Generate Request File from INF File

Write-Host "Generating Certificate Request file..." -ForegroundColor Yellow;
$MYCERTNAME = "$UID" + "_" + "$Date" + ".inf"
New-Item $MYCERTNAME -type file -value $InfFile


certreq -new $path\$MYCERTNAME $path\$ReqFile
    Write-Host " "
Write-Host "Certificate request file for $UID successfully generated!" -foregroundcolor DarkGreen;


# Authentication on PKI: HERE I AM TOTALLY LOST

Connect-CertificationAuthority -ComputerName ca01.company.com
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
     -argumentlist $Login, $Pass

$serverNameOrIp = "192.168.1.1"
Restart-Computer -ComputerName $serverNameOrIp `
             -Authentication default `
             -Credential $cred
             <any other parameters relevant to you>
$cred = new-object -typename System.Management.Automation.PSCredential `
     -argumentlist $username, $password

$serverNameOrIp = "https://pki.mycompany.fr/certsrv/certrqxt.asp"
Restart-Computer -ComputerName $serverNameOrIp `
             -Authentication default `
             -Credential $cred
             <any other parameters relevant to you>


certreq -submit -config "https://pki.mycompany.fr/certsrv/certrqxt.asp"     $path\$ReqFile $path\$UID.cer   
#certreq -submit -config "https://pki.mycompany.fr\certsrv"           $path\$ReqFile $path\$UID.cer

certreq -accept $path\$UID.cer
certutil -exportpfx -p "Welcome123" MY $UID $path\clientcerts\$UID.pfx