Using PowerShell script below, how to check the SSL certificate validity?
I need to modify the script below, so I can get the list of AD server and then check for any SSL certificate that is in the server for its validity.
Note: The server may or not may run IIS, which is why I am not sure how to do it properly.
$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
}
}
windows powershell scripting active-directory windows-scripting
add a comment |
I need to modify the script below, so I can get the list of AD server and then check for any SSL certificate that is in the server for its validity.
Note: The server may or not may run IIS, which is why I am not sure how to do it properly.
$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
}
}
windows powershell scripting active-directory windows-scripting
1
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
1
from what i can tell, you cannot have ANY code ahead of the[CmdletBinding()]
line. you have aprocess
block ... that line looks like it otta be the 1st thing in theprocess
block OR in thebegin
block.
– Lee_Dailey
Nov 20 '18 at 3:23
add a comment |
I need to modify the script below, so I can get the list of AD server and then check for any SSL certificate that is in the server for its validity.
Note: The server may or not may run IIS, which is why I am not sure how to do it properly.
$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
}
}
windows powershell scripting active-directory windows-scripting
I need to modify the script below, so I can get the list of AD server and then check for any SSL certificate that is in the server for its validity.
Note: The server may or not may run IIS, which is why I am not sure how to do it properly.
$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
}
}
windows powershell scripting active-directory windows-scripting
windows powershell scripting active-directory windows-scripting
edited Nov 20 '18 at 22:22


halfer
14.4k758109
14.4k758109
asked Nov 20 '18 at 2:43


Senior Systems EngineerSenior Systems Engineer
282818
282818
1
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
1
from what i can tell, you cannot have ANY code ahead of the[CmdletBinding()]
line. you have aprocess
block ... that line looks like it otta be the 1st thing in theprocess
block OR in thebegin
block.
– Lee_Dailey
Nov 20 '18 at 3:23
add a comment |
1
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
1
from what i can tell, you cannot have ANY code ahead of the[CmdletBinding()]
line. you have aprocess
block ... that line looks like it otta be the 1st thing in theprocess
block OR in thebegin
block.
– Lee_Dailey
Nov 20 '18 at 3:23
1
1
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
1
1
from what i can tell, you cannot have ANY code ahead of the
[CmdletBinding()]
line. you have a process
block ... that line looks like it otta be the 1st thing in the process
block OR in the begin
block.– Lee_Dailey
Nov 20 '18 at 3:23
from what i can tell, you cannot have ANY code ahead of the
[CmdletBinding()]
line. you have a process
block ... that line looks like it otta be the 1st thing in the process
block OR in the begin
block.– Lee_Dailey
Nov 20 '18 at 3:23
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure if you've forgotten to put the function instantiation on top or not, but the following should be the correct format for an advanced function in PowerShell. You can also give the parameter $ComputerName a default value with the Get-ADComputer cmdlet. Try this out to see if this works.
function Get-ADComputerCert {
[CmdletBinding()]
param(
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
$ComputerName = (Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com").Name
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
}
}
}
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385459%2fusing-powershell-script-below-how-to-check-the-ssl-certificate-validity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure if you've forgotten to put the function instantiation on top or not, but the following should be the correct format for an advanced function in PowerShell. You can also give the parameter $ComputerName a default value with the Get-ADComputer cmdlet. Try this out to see if this works.
function Get-ADComputerCert {
[CmdletBinding()]
param(
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
$ComputerName = (Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com").Name
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
}
}
}
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
add a comment |
I'm not sure if you've forgotten to put the function instantiation on top or not, but the following should be the correct format for an advanced function in PowerShell. You can also give the parameter $ComputerName a default value with the Get-ADComputer cmdlet. Try this out to see if this works.
function Get-ADComputerCert {
[CmdletBinding()]
param(
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
$ComputerName = (Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com").Name
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
}
}
}
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
add a comment |
I'm not sure if you've forgotten to put the function instantiation on top or not, but the following should be the correct format for an advanced function in PowerShell. You can also give the parameter $ComputerName a default value with the Get-ADComputer cmdlet. Try this out to see if this works.
function Get-ADComputerCert {
[CmdletBinding()]
param(
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
$ComputerName = (Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com").Name
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
}
}
}
I'm not sure if you've forgotten to put the function instantiation on top or not, but the following should be the correct format for an advanced function in PowerShell. You can also give the parameter $ComputerName a default value with the Get-ADComputer cmdlet. Try this out to see if this works.
function Get-ADComputerCert {
[CmdletBinding()]
param(
[int]$TCPPort = 443,
[int]$Timeoutms = 3000
)
process {
$ComputerName = (Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com").Name
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
}
}
}
edited Nov 20 '18 at 21:39
answered Nov 20 '18 at 3:20


Peter KayPeter Kay
396211
396211
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
add a comment |
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
Still not working Peter. At line:4 char:75 + ... meter(Mandatory, ValueFromPipeline)][string]$ComputerName = Get-ADC ... + ~ Missing expression after '='.
– Senior Systems Engineer
Nov 20 '18 at 5:11
1
1
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
@SeniorSystemsEngineer try to remove the [string] identifier on the parameter. Since get-adcomputer retrieves objects, not strings.
– Peter Kay
Nov 20 '18 at 5:38
1
1
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
@SeniorSystemsEngineer Also, you might need to evaluate the Get-ADComputer as PowerShell is barking at you for not having a complete expression after the $ComputerName. To do that, just enclose the Cmdlet and it’s parameters in parentheses.
– Peter Kay
Nov 20 '18 at 6:28
1
1
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
I already have a function written to do this, which reads the SSL stream using tcpclient class instead so will get certificate details from any IP or FQDN. You could simply pipe get-adcomputer results to it. If you want to take a look I can post here or on my blog for you
– Scepticalist
Nov 20 '18 at 10:34
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
@SeniorSystemsEngineer I just updated my answer and fixed the $ComputerName variable to get the name value string. This should work now.
– Peter Kay
Nov 20 '18 at 21:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385459%2fusing-powershell-script-below-how-to-check-the-ssl-certificate-validity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What issues are you having with this script?
– Peter Kay
Nov 20 '18 at 2:59
This is the error: $ComputerName = Get-ADComputer -Filter {Enabled -eq $True} -SearchBas ... + ~~~~~~~~~~~~~ Unexpected token '$ComputerName' in expression or statement.
– Senior Systems Engineer
Nov 20 '18 at 3:03
1
from what i can tell, you cannot have ANY code ahead of the
[CmdletBinding()]
line. you have aprocess
block ... that line looks like it otta be the 1st thing in theprocess
block OR in thebegin
block.– Lee_Dailey
Nov 20 '18 at 3:23