Last active
November 13, 2022 21:45
-
-
Save mikepfeiffer/b2cc488985e675de7e8c8d38a0943539 to your computer and use it in GitHub Desktop.
PS Function that creates an Azure Service Principal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-Sp { | |
param($Name, $Password) | |
$spParams = @{ | |
StartDate = Get-Date | |
EndDate = Get-Date -Year 2030 | |
Password = $Password | |
} | |
$cred= New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property $spParams | |
$sp = New-AzAdServicePrincipal -DisplayName $Name -PasswordCredential $cred | |
Write-Output $sp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Mike,
I am following your DevOps training course from CloudSkills. This script is not working on cloud shell to create Azure Service Principal. Getting below error message.
New-Object:
Line |
10 | $cred= New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPass …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find type [Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential]: verify that the assembly containing this type is loaded.
New-AzADServicePrincipal:
Line |
11 | … New-AzAdServicePrincipal -DisplayName $Name -PasswordCredential $cred
| ~~~~~
| Cannot bind argument to parameter 'PasswordCredential' because it is null.
Kindly let me know if there is workaround for this?
Thanks,
Kivi