Windows Server 2012R2/2016: HOWTO检查Active Directory PowerShe



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
}

引用这能行吗?我的测试没有显示"正确"。response at '(Import-Module ActiveDirectory -Proxy proxy.verizon.com:80 -ErrorAction Continue -Verbose)'

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 = ".logsstart-$service-$date.log"'

最新更新