Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c中使用ActiveDirectory模块(RSAT工具)#_C#_Powershell_Exchange Server_Cmdlets - Fatal编程技术网

C# 如何在c中使用ActiveDirectory模块(RSAT工具)#

C# 如何在c中使用ActiveDirectory模块(RSAT工具)#,c#,powershell,exchange-server,cmdlets,C#,Powershell,Exchange Server,Cmdlets,我想使用由“Windows PowerShell的Active Directory管理”提供的特定命令。所以我在我的服务器上安装了这个模块 现在,我想在我的代码中使用这些命令。我的项目是在c#-ASP.NET中完成的 下面是我用来调用传统“cmdlet”命令(新建邮箱、设置用户等)的代码: 这个代码工作得很好!伟大的但是假设我想使用“Set ADUser”,这个命令来自ActiveDirectory模块(RSAT工具) 考虑到服务器上已设置了所有内容(模块已安装),我尝试将“新邮箱”更改为“se

我想使用由“Windows PowerShell的Active Directory管理”提供的特定命令。所以我在我的服务器上安装了这个模块

现在,我想在我的代码中使用这些命令。我的项目是在c#-ASP.NET中完成的

下面是我用来调用传统“cmdlet”命令(新建邮箱、设置用户等)的代码:

这个代码工作得很好!伟大的但是假设我想使用“Set ADUser”,这个命令来自ActiveDirectory模块(RSAT工具)

考虑到服务器上已设置了所有内容(模块已安装),我尝试将“新邮箱”更改为“set ADUser”:

运行代码时,出现以下错误:

术语“Set-ADUser”不能识别为cmdlet、函数、脚本文件或可操作程序的名称

这就是我的问题:


如何在c#中从ActiveDirectory模块(RSAT工具)运行命令?(我使用VS 2010)。

正如@JPBlanc在评论部分指出的,您需要确保加载了
ActiveDirectory
PowerShell模块。PowerShell 3.0版及更高版本在默认情况下启用了模块自动加载(可以禁用),但如果您仍以PowerShell 2.0为目标,则必须首先调用:

Import-Module -Name ActiveDirectory;
。。然后才能使用模块内的命令

出于验证的目的,您可以使用
Get Module
命令来确保
ActiveDirectory
模块已导入

Get-Module -Name ActiveDirectory;
如果上述命令返回
$null
,则不导入模块。要验证PowerShell是否可以“查看”ActiveDirectory模块,而无需实际导入,请运行以下命令:

Get-Module -Name ActiveDirectory -ListAvailable;

您应该导入Active Directory模块
“导入模块‘Active Directory’”
您能详细说明如何执行此操作吗?Thank youSet ADUser是来自名为“Active Directory”的PowerShell模块的CmdLet提交。在PowerShell 2.0上,必须先加载Active Directory模块,然后才能使用此CmdLet。从PowerShell 3.0开始,模块是动态加载的。另一个线索是查看项目目标32/64位。不确定Active Directory模块是否可以加载32位目标EXE文件。专门安装RSAT工具。我测试了将其加载到32位PowerShell中,它似乎在2012 R2上工作。
Get-Module -Name ActiveDirectory;
Get-Module -Name ActiveDirectory -ListAvailable;