【发布时间】:2016-12-21 00:00:39
【问题描述】:
我编写了一个 PowerShell 脚本,一个允许 PC Refresh 在 AD 对象上设置 Company、DepartmentNumber 等的应用程序。在开发中一切正常。显然我的机器上安装了 AD。我已将我的应用程序编译为 .exe 并将其放置在网络共享上,技术人员将在其中执行它,因为他们启动新计算机或主要从 Windows 7 刷新到 Windows 10。
问题是新电脑此时不会安装 Active Directory。我需要找到一种方法来安装、导入和运行 Active Directory,就像在启动新计算机或更新计算机时一样。我该如何做到这一点?
下面是我用来导入模块的一些相关代码,如果它存在于机器上。
$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"
}
}
【问题讨论】:
-
这只是模块,我尝试了你的建议,但它不起作用。作为一个测试,我将其放置如下:我收到以下错误:错误:术语“Add-WindowsFeature”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含 pa ERROR: th,请验证路径是否正确并重试。
-
$No_Load = { Add-WindowsFeature net-framework-core Add-WindowsFeature RSAT-AD-PowerShell # 加载 ActiveDirectory 模块,如果它可用 # 检查是否安装了 ActiveDirectory 模块 if ((Get-Module -ListAvailable | where { $_.Name -eq 'ActiveDirectory' }) -eq $null) { $labelDialogRedNewNo.Text += "你需要安装 ActiveDirectory 模块!`n" }
-
现在我得到这个错误:Import-Module : The specified module 'ServerManager' is not loaded because no valid module file was found in any module directory.
-
您在哪个操作系统上运行
Import-Module ServerManager?
标签: powershell active-directory