您如何认证到Live@EDU(outlook.com)在使用导入的PowerShell会话时?
我正在连接到Exchange 2010 forLive@edu通过PowerShell。我可以用标准的方法连接。但是,每次下载和导入会话命令似乎都是浪费,尤其是因为它不在LAN上。此外,有时,这些脚本会将数据返回到web页面,导入时间似乎也很浪费 我找到了如何使用export-PSSession cmdlet导出会话。如果我使用导入模块导入导出的模块,那么除了一个问题外,所有功能都正常工作。当我从模块运行cmdlet时,它希望我通过GUI以交互方式设置密码。我真正想要的是让我的脚本以非交互方式运行,但同时在本地加载模块您如何认证到Live@EDU(outlook.com)在使用导入的PowerShell会话时?,powershell,exchange-server-2010,import-module,outlook.com,Powershell,Exchange Server 2010,Import Module,Outlook.com,我正在连接到Exchange 2010 forLive@edu通过PowerShell。我可以用标准的方法连接。但是,每次下载和导入会话命令似乎都是浪费,尤其是因为它不在LAN上。此外,有时,这些脚本会将数据返回到web页面,导入时间似乎也很浪费 我找到了如何使用export-PSSession cmdlet导出会话。如果我使用导入模块导入导出的模块,那么除了一个问题外,所有功能都正常工作。当我从模块运行cmdlet时,它希望我通过GUI以交互方式设置密码。我真正想要的是让我的脚本以非交互方式运
这可能吗?您面临的问题是,您需要能够隐式地为所有导入的函数设置PSSession。为此,您需要能够运行
Set-PSImplicitRemotingSession
功能
不幸的是,该函数未被导出,因此您无法访问它。要解决此问题,需要打开PSM1文件并将该函数添加到$script:ExportModuleMember
的末尾。现在,当您导入模块时,该函数将能够为所有函数设置PSSession
以下是您的powershell或脚本需要运行什么才能使用任何导入的模块
Import-Module "C:\Credentials.psm1"
Import-Module "C:\ExportedPSSession.psm1"
$Cred = Import-Credential -path C:\Cred.xml
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Authentication Basic -AllowRedirection -Credential $Cred
Set-PSImplicitRemotingSession -PSSession $Session -createdByModule $True
#You can now run any of the imported functions.
凭证。psm1小心!任何可以加载xml文件的人现在都可以模拟您
我让那部分工作起来了。我遵循他的代码使BPO正常工作。但是,BPOS cmdlet采用凭证参数。然而,对于Live@edu我看不到任何指定凭证的方法。如果我按照这些说明加载一个模块,或者加载一个模块并按照这些说明加载,它仍然会以交互方式请求密码。PowerShell以交互方式向您请求Cred,或者某些其他表单/进程在PS之外发出此请求?PowerShell以交互方式请求Cred。用户名已预先填入用于导出会话的用户。已更新我的anwser。。。事实证明,您需要编辑psm1文件以导出附加函数,以便设置ps会话信息。您不需要导出该函数,您可以调用以下模块的私有函数:&(gmo“NameOfModule”)set PSImplicitMotingSession-PSSession$session-createdByModule$True
function Export-Credential($cred, $path) {
$cred = $cred | Select-Object *
$cred.password = $cred.Password | ConvertFrom-SecureString
$obj = New-Object psobject
$obj | Add-Member -MemberType NoteProperty -Name UserName -Value $cred.username
$obj | Add-Member -MemberType NoteProperty -Name Password -Value $cred.password
$obj | Export-Clixml $path
}
function Import-Credential($path) {
$obj = Import-Clixml $path
$obj.password = $obj.Password | ConvertTo-SecureString
return New-Object system.Management.Automation.PSCredential( $obj.username, $obj.password)
}