Author Posts

December 18, 2015 at 6:21 am

Hi All

i have the following script which works and displays very nicley when ran, but is extremely messy etc... im trying to clean this up, lets start with this

$date = "09/10/2015"

Write-host
Write-host
Write-host "EURXMBS05 Updates"
Get-HotFix -ComputerName eurxmbs05 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$xmbs05 = Get-HotFix -ComputerName eurxmbs05 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $xmbs05
Write-host

Write-host "EURXMBS06 Updates"
Get-HotFix -ComputerName eurxmbs06 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$xmbs06 = Get-HotFix -ComputerName eurxmbs06 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $xmbs06
Write-host

Write-host "EURXHUB01 Updates"
Get-HotFix -ComputerName eurxhub01 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$hub01 = Get-HotFix -ComputerName eurxhub01 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hub01
Write-host

Write-host "EURXHUB02 Updates"
Get-HotFix -ComputerName eurxhub02 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$hub02 = Get-HotFix -ComputerName eurxhub02 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hub02
Write-host

Write-host "EURXHUB03 Updates"
Get-HotFix -ComputerName eurxhub03 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$hub03 = Get-HotFix -ComputerName eurxhub03 |? installedon -eq $date | measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hub03
Write-host

Write-host "EURXHTS01 Updates"
Get-HotFix -ComputerName eurxhTS01 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$HTS01 = Get-HotFix -ComputerName eurxhTS01 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hts01
Write-host

Write-host "EURXHTS02 Updates"
Get-HotFix -ComputerName eurxhTS02 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$hts02 = Get-HotFix -ComputerName eurxhTS02 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hts02
Write-host

Write-host "EURXHTS03 Updates"
Get-HotFix -ComputerName eurxhTS03 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$HTS03 = Get-HotFix -ComputerName eurxhTS03 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $hts03
Write-host

Write-host "EURXCASL1 Updates"
Get-HotFix -ComputerName eurxCASl1 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$Casl1 = Get-HotFix -ComputerName eurxCASl1 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $CASl1
Write-host

Write-host "EURXCASL2 Updates"
Get-HotFix -ComputerName eurxCASl2 |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
$Casl2 = Get-HotFix -ComputerName eurxCASl2 |? installedon -eq $date |measure | Select-Object count
Write-Host
Write-host "Update Count"
Write-host $CASl2
Write-host

i am trying the below but not getting the results i want

#Get Machines by role
$cas = Get-QADComputer -LdapFilter '(Name=eurxca*)' | select name
$hub = Get-QADComputer -LdapFilter '(Name=eurxhu*)' | select name
$hts = Get-QADComputer -LdapFilter '(Name=eurxht*)' | select name
$Active05 = Get-QADComputer -LdapFilter '(Name=eurxmbs05)' | select name
$Active06 = Get-QADComputer -LdapFilter '(Name=eurxmbs05)' | select name
$pub = Get-QADComputer -LdapFilter '(Name=eurxpub*)' | select name

# Combine the Above
$Machines = $cas,$hub,$hts,$Active05,$Active06,$pub

#UK Date Prefix 
$date = "18/12/2015"

$machines | ForEach-Object {
Get-HotFix  |? installedon -eq $date | Select-Object description,hotfixid,installedby,
@{l="InstalledOn";e={
[DateTime]::Parse($_.psbase.properties["installedon"].value,
$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}
Get-HotFix |? installedon -eq $date |measure | Select-Object count
}

the output i would like to be in the below format is a list of the updates etc... and a count at the bottom, i also had problems adding the count in a single command hence running it twice

December 18, 2015 at 6:40 am

A couple of immediate points. When you're getting the computer name you should use select -expandproperty name. That will give you just the name. You're currently getting an object. Also if you already know the names why bother using get-QADComputer ?

Get-Hotfix – will be looking at the local computer as you don't tell it to use the names on the pipeline.

Don't use ? as an alias for Where-Object in scripts.

your loop should look something like this

$machines | ForEach-Object {

    $hf = Get-HotFix -ComputerName $psitem  |Where-Object installedon -eq $date 
    
    $hf | Select-Object description,hotfixid,installedby,
    @{l='InstalledOn'; 
        e={[DateTime]::Parse($_.psbase.properties['installedon'].value,
    $([System.Globalization.CultureInfo]::GetCultureInfo('en-US')))}}
    
    $hf |Measure-Object | Select-Object count
}

December 18, 2015 at 6:52 am

That's a whole kennel of puppies:-)

December 18, 2015 at 6:58 am

Thanks richard, i know the names but was just trying to allow the script to cope with the addition of any new cas or MBX servers

the loop looks great, however it does not display the name of the server that the updates have applied to, any idea how i can retrive that ?

really appreciate the help thanks

December 18, 2015 at 7:05 am

add source to the select statement.

note the columns(properties) of get-hotfix |select -First 1

check out the other properties

get-hotfix |select -First 1 |gm