if {%1} equ {/?} goto USAGEif {%1} equ {-?} goto USAGEif {%1} equ {?} goto USAGEif {%1} equ {} goto USAGE
set subjectname=%1set certpath=%systemdrive%\OMCertificates
mkdir %certpath%
rem Get the CA's certcertutil -f -config dc.lan.com\SCOMCA -ca.cert %certpath%\CACertificate.cer
rem Move the CA's cert to the "Trusted Root Authorities" storecertutil -f -addstore Root %certpath%\CACertificate.cer
rem Create an INF request file with the specified subjectnamedel %certpath%\RequestConfig.infecho [NewRequest] > %certpath%\RequestConfig.infecho Subject="CN=%subjectname%" >> %certpath%\RequestConfig.infecho Exportable=TRUE >> %certpath%\RequestConfig.infecho KeyLength=1024 >> %certpath%\RequestConfig.infecho KeySpec=1 >> %certpath%\RequestConfig.infecho KeyUsage=0xf0 >> %certpath%\RequestConfig.infecho MachineKeySet=TRUE >> %certpath%\RequestConfig.infecho [EnhancedKeyUsageExtension] >> %certpath%\RequestConfig.infecho OID=1.3.6.1.5.5.7.3.1 >> %certpath%\RequestConfig.infecho OID=1.3.6.1.5.5.7.3.2 >> %certpath%\RequestConfig.inf
rem Create a binary request file from the INF
del %certpath%\BinaryRequest.reqCertReq -New -f %certpath%\RequestConfig.inf %certpath%\BinaryRequest.req
rem Submit the request to our CA and save the certificateCertReq -Submit -f -config "dc.lan.com\SCOMCA" %certpath%\BinaryRequest.req %certpath%\NewCertificate.cer
rem This step needed to import the private key. Also puts the certificate in the local computer personal store.certreq -accept %certpath%\NewCertificate.cer
MOMCertImport.exe /SubjectName %subjectname%
goto END
:USAGEecho.echo GetCert.cmd FQDN_of_machineecho Example: GetCert.cmd Computer01.Contoso.comecho Gets and installs a cert from CA cahost.contoso.com (CorpCA) appropriate for OMv3, and also gets and installs CA cert so this CA is trusted.echo.
:END