【发布时间】:2022-01-31 13:49:08
【问题描述】:
在我的 asp.net core 5 项目中,我想执行下面的 ps 脚本。此脚本可以在本机 powershell 中执行而不会出错。而且我可以在我的项目上下文中运行简单的 ps 脚本。但是,如果我通过 IIS Express(与本机 powershell 相同的机器)运行此脚本,则会引发以下错误消息:
无法验证参数“会话”的参数。参数为空。 为参数提供一个有效值,然后尝试运行 再次命令。
消息属于Import-PSSession 命令。如何在 asp.net core 项目上下文中运行脚本?
$Username = 'user'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
$ExchangeFQDN = 'exchange.domain'
$ConnectionURI = "http://$($ExchangeFQDN)/powershell"
try{
$mSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $ConnectionURI -Credential $Cred -Authentication Kerberos
Import-PSSession $mSession -DisableNameChecking
}catch{
echo $_
}
【问题讨论】:
标签: powershell asp.net-core exchangewebservices