如何从我的脚本设置凭据,每次开发时都要输入我的用户和密码很烦人。
基本上我正在寻找像Set-Credential这样的功能。
此致
答案 0 :(得分:1)
您可以使用此脚本:
Set-ExecutionPolicy unrestricted
$cred = Get-Credential
$O365 = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic –AllowRedirection
$importcmd = Import-PSSession $O365
$importcmd.ExportedFunctions.Count
或者您可以使用此脚本 - 类似:
$domain=YOUR_DOMAIN
$userName = "YOUR_LOGIN@$domain.onmicrosoft.com" ($domain change to your domain)
$password = "PASSWORD"
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $securePassword
Connect-MsolService -Credential $credential
答案 1 :(得分:0)
$Cred = Get-Credential
Import-Module MSOnline
Connect-MsolService -Credential $cred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
$User = “<user@domain.com>”
$Pass = “<password>”
$Cred = New-Object System.Management.Automation.PsCredential($User,(ConvertTo-SecureString $Pass -AsPlainText -Force))
Import-Module MSOnline
Connect-MsolService -Credential $Cred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session