2012-01-28 111 views
0

我如何从我的脚本设置凭据,每次开发时都不断输入我的用户名和密码令人讨厌。办公室365设置凭据

基本上我正在寻找像Set-Credential这样的函数。

问候,

回答

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 = "[email protected]$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 
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 = “<[email protected]>” 
$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