How can i run powershell scripts with puppet.

asked 2016-07-14 07:23:42 -0500

I have a powershell script but i need this script to work with puppet automatic and to write reports every week in foreman.


$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0,$HistoryCount) | ForEach-Object -Process {
$Title = $null
if($.Title -match "(KB\d{6,7})"){
#Split returns an array of strings
$Title = ($
.Title -split '.((KB\d{6,7}))')[1]
}else{
$Title = $_.Title
}
$Result = $null
Switch ($_.ResultCode)
{
0 { $Result = 'NotStarted'}
1 { $Result = 'InProgress' }
2 { $Result = 'Succeeded' }
3 { $Result = 'SucceededWithErrors' }
4 { $Result = 'Failed' }
5 { $Result = 'Aborted' }
default { $Result = $_ }
}
$KB = Get-HotFix | get-random | select -ExpandProperty HotFixID $Des = Get-HotFix | get-random | select -ExpandProperty Description
New-Object -TypeName PSObject -Property @{
KBID = $KB Updatename = $Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) | where-object { $_.Title -like „
$KB*“ } | select -ExpandProperty Title
InstalledOn = Get-Date -Date $_.Date;
Status = $Result
InstalledBy = Get-HotFix | get-random | select -ExpandProperty InstalledBy Description = $Des

}

} | Sort-Object -Descending:$true -Property InstalledOn |
Select-Object -Property * -ExcludeProperty Name | Format-Table -AutoSize -Wrap

edit retag flag offensive close merge delete

Comments

Still sounds like you need a custom fact as per your previous comment in https://ask.puppet.com/question/27150/getting-windows-updates-installation-history/

GlennSarti gravatar imageGlennSarti ( 2016-07-21 13:02:50 -0500 )edit