@Richkm
Thank you for following up on this!
I tested your script in my tenant to confirm that the Secret was being retrieved correctly and found that you might have to use ConvertFrom-SecureString -AsPlainText
or $SecretDetail.SecretValueText
within the $Cred
parameter. Since you're using the same secret as $password
, you can also try replacing $SecretDetail.SecretValue
with $password
.
$Cred = New-Object System.Management.Automation.PSCredential ("SCCMADMIN@testoutlook.onmicrosoft.com", $SecretDetail.SecretValue)
Findings:
#Get-AzKeyVaultSecret works as expected showing the Secret was retrieved successfully.
$password =Get-AzKeyVaultSecret -VaultName "jtranKeyVault" -Name "testSecret" -AsPlainText
Write-Host $password
#The SecretDetail parameter is retrieving the ...PSKeyVaultSecret value, that isn't in PlainText and is Null.
$SecretDetail = Get-AzKeyVaultSecret -VaultName "jtranKeyVault" -Name "testSecret"
Write-Host $SecretDetail
Write-Host $SecretDetail.SecretValueText
Since $SecretDetail
is Null, $Cred
is possibly failing to login which could be why you're receiving the "Access is denied" error referencing the Rename-Computer
command.
If you have any other questions or are still having issues with this, please let me know.
Thank you for your time and patience throughout this issue.
----------
Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.