【发布时间】:2019-04-22 10:50:49
【问题描述】:
我需要修改下面的脚本,这样我才能得到 AD 服务器的列表,然后检查服务器中的任何 SSL 证书的有效性。
注意:服务器可能运行也可能不运行 IIS,这就是为什么我不确定如何正确执行。
$ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com"
[CmdletBinding()]
param(
[parameter(Mandatory, ValueFromPipeline)][string[]]$ComputerName,
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
foreach ($computer in $computerName) {
$port = $TCPPort
write-verbose "$computer`: Connecting on port $port"
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$req = [Net.HttpWebRequest]::Create("https://$computer`:$port/")
$req.Timeout = $Timeoutms
try {$req.GetResponse() | Out-Null} catch {write-error "Couldn't connect to $computer on port $port"; continue}
if (!($req.ServicePoint.Certificate)) {write-error "No Certificate returned on $computer"; continue}
$certinfo = $req.ServicePoint.Certificate
$returnobj = [ordered]@{
ComputerName = $computer;
Port = $port;
Subject = $certinfo.Subject;
Thumbprint = $certinfo.GetCertHashString();
Issuer = $certinfo.Issuer;
SerialNumber = $certinfo.GetSerialNumberString();
Issued = [DateTime]$certinfo.GetEffectiveDateString();
Expires = [DateTime]$certinfo.GetExpirationDateString();
}
new-object PSCustomObject -Property $returnobj
}
}
【问题讨论】:
-
这个脚本有什么问题?
-
这是错误:$ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '表达式或语句中的 $ComputerName'。
-
据我所知,
[CmdletBinding()]行之前不能有任何代码。你有一个process块...该行看起来应该是process块或begin块中的第一件事。
标签: windows powershell scripting active-directory windows-scripting