how does this script work in powershell 2.0

Import-Module -Name WebAdministration

$servers = Get-Content D:\Utilidades\servidores.txt

foreach ($server in $servers) { Invoke-Command -Computername $server -ScriptBlock { import-module WebAdministration; Get-ChildItem -Path IIS:SSLBindings | ForEach-Object -Process ` { if ($_.Sites) {

$certificate = Get-ChildItem -Path CERT:LocalMachine/My | Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint [PsCustomObject]@{ Sites = $_.Sites.Value FriendlyName = $certificate.FriendlyName Fecha_de_Expiracion = $certificate.NotAfter Thumbprint = $certificate.Thumbprint } } } } | Select Sites,FriendlyName,Fecha_de_Expiracion,Thumbprint,PSComputerName | Export-Csv -force -Append D:\Utilidades\Output.csv }

  • 1
    What part is confusing you? [PsCustomObject]@{} is basically the same as New-Object PSObject -Property @{}. – Zoredache Oct 30 '17 at 21:26
  • The problem is this script doesn't work with 2008 servers in the txt file. – Jcastrou Oct 31 '17 at 14:53
  • 1
    Doesn't work how? What errors do you get? Edit the question, and include error messages. You mention '2008', but do you mean '2008r2'? Earlier version of 2008 are EOL. Have you updated the management framework on your systems? What is the Powershell version on those servers. – Zoredache Oct 31 '17 at 19:35

I imagine you're not getting any output because the path on your PSDrives is missing the backslash

CERT:LocalMachine > CERT:\LocalMachine
IIS:SSL bindings > IIS:\SSLBindings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.