1

我如何从我的脚本中设置凭据,在开发时每次都输入我的用户和密码很烦人。

基本上我正在寻找一些像 Set-Credential 这样的功能。

问候,

4

2 回答 2

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
于 2012-11-14T10:47:05.120 回答
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
于 2014-11-20T03:40:19.660 回答