2012-01-28 341 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