Repository navigation
Expand file tree
/
Copy pathQuery-SysKBID.ps1
More file actions
50 lines (40 loc) · 1.4 KB
/
Copy pathQuery-SysKBID.ps1
File metadata and controls
50 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Script written by Payton Flint
# See https://paytonflint.com/parallel-vs-serial-execution-improving-powershell-script-performance/
# Parallel Execution:
# Set KB ID variable
$KBID = <Insert KBID>
# Identify location of script
$ScriptPath = Split-Path ($MyInvocation.MyCommand.Path) -Parent
# Set systems list location
$AllSystems = Get-Content "$ScriptPath\DeviceList.txt"
# KBIDQuery workflow
workflow KBIDQuery {
# Set workflow parameters
Param (
[string[]]$KBID,
[string[]]$ScriptPath,
[string[]]$AllSystems
)
# Parallel Foreach loop set to $Output to write to .CSV later
$Output = Foreach -Parallel ($system in $AllSystems) {
# InlineScript to use variables
inlinescript {
# Set compliance based on whether KBID is present on system
if ((Get-HotFix -ComputerName $Using:system).Where({$_.HotFixID -like $Using:KBID})){
$Compliance = $true
}
else{
$Compliance = $false
}
# Create table
[PSCustomObject]@{
Name = $Using:system
Length = $Compliance
}
}
}
# Write output to .CSV at parent directory
$Output | Export-Csv -Path "$ScriptPath\KBIDQueryParallelOutput.csv" -NoTypeInformation
}
# Call workflow
KBIDQuery -KBID $KBID -ScriptPath $ScriptPath -AllSystems $AllSystems