Hi,
I’m hoping that there’s a powershell wiz who’s able to give me a little bit of assistance on a Post Deployment Script that I’m trying to develop and get working. It’s 90% there, just failing at the last hurdle.
I’m trying to get Certify the Web to upload a certificate to Azure Application Proxy. I’ve got the script to the stage where it adds a password to the pfx file passed to it from Certify, and connects to AzureAD without a problem, and I can even get the ObjectID from Azure which suggests that it’s connected OK. However when I’m running the Set-AzureADApplicationProxyApplicationCustomDomainCertificate module, I’m getting an ‘Object reference not set to an instance of an object’ error. Now this is happening both when I’m running the script and when I’m running through the steps manually as well.
Any help would be appreciated.
Cheers
Jim
param($result)
set-alias ps64 “$env:C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe”
ps64 -args $result -command {
$result = $args[0]
#Certificate Location Passed from CertifyTheWeb Application
$pfxpath = $result.ManagedItem.CertificatePath
#Location of the new certificate
$pfxNewPath = “c:\scripts\remotedesktop.pfx”
#Gets the Certificate passed Location Passed above
$mypfx = Get-PfxData -FilePath $pfxpath
#Text String to password protect the cert
$PfxPassword = ConvertTo-SecureString -String [REMOVED] -AsPlainText -Force
#Export the provided certificate to a new file with password protection (needed to be able to upload to Azure Application Proxy)
Export-PfxCertificate -PFXData $mypfx -FilePath $pfxNewPath -Password $PfxPassword
#Connect to AzureAD by obtaining a new refresh token
The refresh token
$refresh_token="[REMOVED]"
Tenant id and account id
$tenant_id = “[REMOVED]”
$account = “[REMOVED]”
1b730954-1685-4b74-9bfd-dac224a7b894 is a public client from Microsoft
$clientId = “1b730954-1685-4b74-9bfd-dac224a7b894”
$uri = “https://login.microsoftonline.com/${tenant_id}/oauth2/token”
$body = @{grant_type=‘refresh_token’;resource=‘https://graph.windows.net’;client_id=$clientId;refresh_token=$refresh_token}
$result = Invoke-RestMethod -Method Post -Uri $uri -Body $body
$accessToken = $result.access_token
Connect to AAD using the above details
Connect-AzureAD -TenantId $tenant_id -AadAccessToken $accessToken -AccountId $account
#Gets the AzureADApplication Object ID for the Remote Desktop App
$WebsiteAppName = “Remote Desktop”
$webAppId = (Get-AzureADApplication -SearchString $WebsiteAppName -ea Stop).ObjectId
Set-AzureADApplicationProxyApplicationCustomDomainCertificate -ObjectId $webAppId
-PfxFilePath $pfxNewPath `
-Password $PfxPassword
#Disconnects from Azure AD and cleans up Password Protected PFX file as no longer needed.
Disconnect-AzureAD
Remove-Item $pfxNewPath
}