# convert SecureString to a plain text # (the system method requires clear-text) $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# test password $PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($context, $Domain) $PrincipalContext.ValidateCredentials($UserName,$plain) }
if ($PSVersionTable.PSEdition -eq'Desktop'-and (Get-Module-Name AzureRM -ListAvailable)) { Write-Warning'AzureRM and Az modules installed at the same time is not supported.') } else { Install-Module-Name Az -AllowClobber-Scope CurrentUser }
在 Windows PowerShell 上,如果您已经安装了较旧的 “AzureRM” 模块,不建议再安装 “Az” 模块,因此上面的代码检查 “AzureRM” 模块是否存在,仅当 Windows PowerShell 中不存在该模块时下载并安装新的 “Az” 模块。