2014-02-12 78 views
1

我试图通过PowerShell在Exchange上执行一些操作(Office 365)。通过PowerShell连接Office 365 Exchange Online

首先,我创建了一个新的PowerShell会话和导出的模块,以本地为“O365”,以便在以后的任何操作我没有必要使用进口PSSession可下载所需要的模块

$cred = Get-Credential 
$s = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection 
Export-PsSession -session $s -outputModule o365 

现在,我正在创建新会话并导入现有模块“o365”。

$cred = Get-Credential 
$s = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection 
Import-Module o365 
Get-DistributionGroup 

在运行命令 “GET-DistributionGroup”,PowerShell的提示我再次进入办公室365个凭据。是否有可能避免再次输入凭据?我不想使用Import-PsSession,因为它需要更多时间。

回答

2

这是提示,因为你问它每次。我会通过创建一个新对象来设置$ cred。

#Initiate Get-Credential cmdlet and store inputs 
$getcred = Get-Credential 
$username = $getcred.UserName 
$password = $getcred.Password 

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password 

如果你把上面的在它自己的功能,你不会有重新定义$ getcred变量的问题。 (这对大多数人来说是显而易见的,但我认为我会覆盖那个基地)

+0

我申请了上面的一个,但它仍然要求输入密码。现在我正在使用适合需要的Enter-PsSession,并解决了不需要使用Import-PsSession的问题。 – prabna

相关问题