问题描述
Hi Experts。
我无法在Csharp ASP.Net Web服务中加载lync模块。模块加载代码如下所示。
string exchServerAdmin =" admin@admin-test.com"
$
string exchServerPwd =" abcd123"
string url =" http://admin-test.test.com/powershell"
$
string shellurl =" http://schemas.microsoft.com/ powershell / Microsoft.Exchange" ;;
PSCredential creds =
System.Security.SecureString securePassword = new System.Security.SecureString();
foreach(char c in pwd.ToCharArray())
{
securePassword.AppendChar(c);
}
creds = new PSCredential(userid,securePassword);           
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(url),shellurl,creds);
$
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
RunSpacePool runSpacePool = RunspaceFactory.CreateRunspacePool(1,3,connectionInfo);
runSpacePool.Open();
PowerShell pshell = PowerShell.Create();
$
pshell.RunspacePool = runSpacePool;
pshell.AddScript(@" Import -Module Lync");
IAsyncResult aresult = pshell.BeginInvoke();
PSDataCollection< PSObject> results = pshell.EndInvoke(aresult);
$
if(pshell.Streams.Error!= null&& pshell.Streams.Error.Count == 0)
{
logger.Debug(操作+" Reslts " + results.Count);
logger.Debug(操作+"ProcessResponse已成功执行"+ results.Count);
}
else
; {
if(pshell.Streams.Error!= null)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
logger.Error(操作+"发生错误");
foreach(pshell.Streams.Error中的ErrorRecord错误)
{
logger.Error(operation,error.Exception);
}
}
}
在加载Lync模块时运行上面的代码时出现以下异常。下面给出了异常详细信息。
System.Management.Automation.RemoteException:术语"Import-Module"未被识别为cmdlet,函数,脚本文件或可操作的名称程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确并再次尝试
。
任何想法为什么会抛出此异常。
非常感谢帮助。
Hi Experts.
I couldn't able to load the lync module in the Csharp ASP.Net Web Service. The module loading code is given below.
string exchServerAdmin = "admin@admin-test.com"
string exchServerPwd = "abcd123"
string url="http://admin-test.test.com/powershell"
string shellurl = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
PSCredential creds =
System.Security.SecureString securePassword = new System.Security.SecureString();
foreach (char c in pwd.ToCharArray())
{
securePassword.AppendChar(c);
}
creds = new PSCredential(userid, securePassword);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(url),shellurl, creds);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
RunSpacePool runSpacePool = RunspaceFactory.CreateRunspacePool(1,3, connectionInfo);
runSpacePool.Open();
PowerShell pshell = PowerShell.Create();
pshell.RunspacePool = runSpacePool;
pshell.AddScript(@"Import-Module Lync");
IAsyncResult aresult = pshell.BeginInvoke();
PSDataCollection<PSObject> results = pshell.EndInvoke(aresult);
if (pshell.Streams.Error != null && pshell.Streams.Error.Count == 0)
{
logger.Debug(operation + "Reslts " + results.Count);
logger.Debug(operation + "ProcessResponse Executed Successfully " + results.Count);
}
else
{
if (pshell.Streams.Error != null)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
logger.Error(operation +" Errors occured");
foreach (ErrorRecord error in pshell.Streams.Error)
{
logger.Error(operation,error.Exception);
}
}
}
I am getting the following exception while running the above code while loading the Lync module. The exception details are given below.
System.Management.Automation.RemoteException: The term 'Import-Module' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Any Idea Why this Exception is throwing.
Help is Greatly appreciated.
这篇关于术语“导入模块”不被识别为cmdlet的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!