活动目录模块 [英] Active Directory Module
问题描述
我编写了一个PowerShell脚本,该应用程序允许PC Refresh设置 Company
, DepartmentNumber
等。在AD对象上。在开发中,一切正常。显然我的机器上安装了AD。我已经将我的应用程序编译为.exe并将其放置在网络共享上,技术人员将在启动新计算机或从Windows 7刷新到Windows 10时从那里执行该应用程序。
I have written a PowerShell script, an application that allow PC Refresh to set Company
, DepartmentNumber
, etc. on an AD object. In development everthing works fine. Obviously I have AD installed on my machine. I have compiled my app to a .exe and placed it on a network share where the techs will execute it from there as they start up a new computer or refresh from Windows 7 to Windows 10 mostly.
问题是新PC此时将没有安装Active Directory。我需要找到一种方法来安装我的应用程序,在启动新计算机或刷新计算机时导入和运行Active Directory。我该怎么做呢?
The problem is the new PC will not have Active Directory installed at this point in time. I need to find a way to have my app intall, import and run Active Directory as on start up of new or refreshed computers. How do I accomplish this?
下面是一些我用来导入模块的相关代码,如果模块存在于机器中。
Below is some relevant code I use to import the module if it exist on the machine.
$RestoreForm_Load = {
# Load the ActiveDirectory module if it's available
# Check if the ActiveDirectory module is installed
if ((Get-Module -ListAvailable | where { $_.Name -eq 'ActiveDirectory' }) -eq $null) {
$labelDialogRedRestore.Text += "You need to install the ActiveDirectory module!`n"
} else {
# Check if the ActiveDirectory module is allready Imported
if ((Get-Module ActiveDirectory) -eq $null) {
Import-Module ActiveDirectory -ErrorAction 'SilentlyContinue'
$labelDialogGreenRestore.Text += "ActiveDirectory module imported`n"
} else {
$labelDialogGreenRestore.Text += "ActiveDirectory allready imported`n"
}
}
推荐答案
您可以使用以下命令在脚本中安装模块以下命令:
You could install the module in your script with the following command:
Add-WindowsFeature RSAT-AD-PowerShell
请注意,此功能也需要.NET Framework 3.5.1功能,可以使用以下命令进行安装:
Note that this feature requires the .NET Framework 3.5.1 feature too which can be installed with the following command:
Add-WindowsFeature net-framework-core
这篇关于活动目录模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!