0

Windows Server 2012R2/2016:如何使用 Get-WindowsFeature 检查 Active Directory PowerShell 模块

我需要一种方法来确保我运行 AD 脚本的 Windows 2012R2/2016 服务器已导入 Active-Directory,如果没有则安装它

#Check if AD is still installed
if (Import-Module ActiveDirectory -Proxy proxy.verizon.com:80 -ErrorAction Continue -Verbose)
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Import-Module ActiveDirectory -Proxy proxy.verizon.com:80
}
else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Get-WindowsFeature -Name RSAT-AD-PowerShell|Install-Windowsfeature -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Import-Module ActiveDirectory -Proxy proxy.verizon.com:80
}

Blockquote 这行得通吗?我的测试在“(Import-Module ActiveDirectory -Proxy proxy.verizon.com:80 -ErrorAction Continue -Verbose)”处没有表明“真实”响应

4

1 回答 1

0

Windows Server 2012R2/2016:如何使用 Get-WindowsFeature 检查 Active Directory PowerShell 模块

#Check if AD is still installed
$installed = Get-WindowsFeature -LogPath $log -InformationAction Continue -Name RSAT-AD-PowerShell
if ($installed.Installed)
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Import-Module ActiveDirectory -Verbose -NoClobber -WarningAction Continue -InformationAction Continue -ErrorAction Continue
}
else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Get-WindowsFeature $log -Name RSAT-AD-PowerShell|Install-Windowsfeature -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Import-Module ActiveDirectory -Verbose -NoClobber -WarningAction Continue -InformationAction Continue -ErrorAction Continue
}

#The $log is set in your script header, like this:
"$date = get-date -uformat "%m%d%y-%H"
$day = Get-Date -Format yyyyMMdd
$Service = "ServiceNameHere"
$log = ".\logs\start-$service-$date.log"'
于 2021-09-01T14:38:06.463 回答