Forum Discussion
Gurdev Singh
Oct 21, 2022Iron Contributor
Connect to SPO from Azure automation runbook using a certificate
How to connect to SPO using Pnp powershell Connect-PnpOnline using a certificate with script being executed from Azure automation runbook. I have exported a self-signed certificate and uploaded t...
Gurdev Singh
Jun 01, 2023Iron Contributor
Yep...I can confirm this is all working for me now. So, essentially, the process I use is
1. Create a self-signed certificate, you can also get a proper one if requirements justify that
2. Export the certificate private key pfx and the public key cer separately
3. Add the public key cer to Azure AD application
4. In automation account, upload the pfx certificate, you would need to provide the pfx password and make sure you select the export switch
5. Create a credential variable in automation account. Username is the appID of Azure AD application and password is the pfx password
6. Use the code in my post above to export the certificate, and add it automation account temp location. You should then be able to use it with Connect-PnPOnline
1. Create a self-signed certificate, you can also get a proper one if requirements justify that
2. Export the certificate private key pfx and the public key cer separately
3. Add the public key cer to Azure AD application
4. In automation account, upload the pfx certificate, you would need to provide the pfx password and make sure you select the export switch
5. Create a credential variable in automation account. Username is the appID of Azure AD application and password is the pfx password
6. Use the code in my post above to export the certificate, and add it automation account temp location. You should then be able to use it with Connect-PnPOnline
Soumyadeep2201
Jun 02, 2023Copper Contributor
Thanks for the reply. as you mentioned to store the certificate in temp location of automation account
but while doing the same
$certificatePath = "$env:TEMP\temp.pfx";
$pfxCertificate = $certificate.Export(3, $certificatePassword);
if(Test-Path $certificatePath){
Remove-Item -Path $certificatePath;
}
Set-Content -Value $pfxCertificate -Path $certificatePath -Encoding Byte;Certificate is getting stored in C:\Windows\Temp folder not sure how Azure Runbook will refer to this location and after that its giving me below error
"
Cannot find the requested object
The specified certificate at 'C:\Windows\TEMP\temp.pfx' could not be read. The certificate could be corrupt or it may require a password which has not been provided or is incorrect