在本文https://sabin.io/blog/adding-an-azure-active-directory-application-and-key-using-powershell/之后,我正在Azure Active Directory Application
中使用Azure PowerShell
创建Visual Studio Code
。
我修改了代码以使用Az
模块而不是AzureRM
,但是却出现异常
New-Object : Cannot find type [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADPasswordCredential]: verify that the assembly containing this type is loaded.
PowerShell
function Create-AesManagedObject($key, $IV) {
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
$aesManaged.BlockSize = 128
$aesManaged.KeySize = 256
if ($IV) {
if ($IV.getType().Name -eq "String") {
$aesManaged.IV = [System.Convert]::FromBase64String($IV)
}
else {
$aesManaged.IV = $IV
}
}
if ($key) {
if ($key.getType().Name -eq "String") {
$aesManaged.Key = [System.Convert]::FromBase64String($key)
}
else {
$aesManaged.Key = $key
}
}
$aesManaged
}
function Create-AesKey() {
$aesManaged = Create-AesManagedObject
$aesManaged.GenerateKey()
[System.Convert]::ToBase64String($aesManaged.Key)
}
#Create the 44-character key value
$keyValue = Create-AesKey
$psadCredential = New-Object Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADPasswordCredential
$startDate = Get-Date
$psadCredential.StartDate = $startDate
$psadCredential.EndDate = $startDate.AddYears(1)
$psadCredential.KeyId = [guid]::NewGuid()
$psadCredential.Password = $KeyValue
$ApplicationURI = "https://xxx.xxx/xxxx"
New-AzADApplication –DisplayName “MyNewApp2”`
-HomePage $ApplicationURI `
-IdentifierUris $ApplicationURI `
-PasswordCredentials $psadCredential
$keyValue | out-file “c:\someplace\keyvalue.txt”
我需要知道如何更换
$psadCredential = New-Object Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADPasswordCredential
与兼容并且可以在Az
模块中使用的东西
答案 0 :(得分:1)
使用article尝试使用此代码$psadCredential = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential
。
答案 1 :(得分:0)
尝试使用New-AzureRmADAppCredential
代替New-Object Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADPasswordCredential
。
参考:https://github.com/Azure/azure-powershell/issues/4491
编辑 __________________________________________________
如果选择这样做,则可以启用别名以与新的AZ模块一起使用,并且仍使用旧的cmdlet名称。参考:https://docs.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-2.4.0
但是我认为这也许是您想要的。 New-AzADAppCredential
答案 2 :(得分:0)
您可以使用:
Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential
并且可以使用
导入Import-Module Az.Resources