-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-SCCMStatus.ps1
50 lines (43 loc) · 1.87 KB
/
get-SCCMStatus.ps1
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
param(
[string]$ComputerName
)
$arch = get-wmiobject win32_operatingsystem -computer $ComputerName | select -ExpandProperty OSArchitecture
$HKLMPath = ""
$cutLine = 0
$cutLine = 2
if($arch -eq "64-bit"){
$HKLMPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System"
$cutLine = 9
}else{
$HKLMPath = "HKLM:\Software\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System"
$cutLine = 8
}
function get-{
$list = Invoke-Command -ComputerName $ComputerName -scriptblock {
param($regpath)
$PackageID = Get-ChildItem $regpath | select -ExpandProperty name | foreach{$_.split('\')[9]}
foreach($PKID in $PackageID ){
$GUID = Get-ChildItem $regpath\$PKID | select -ExpandProperty name | foreach{$_.split('\')[10]}
foreach($GID in $GUID){
$APPInfo = Get-ItemProperty $regpath\$PKID\$GID
$APPInfo | Add-Member -type NoteProperty -Name PKID -Value $PKID
$appInfo
}
}
} -ArgumentList $HKLMPath | select PKID,_ProgramID,_State,_RunStartTime,SuccessOrFailureCode,SuccessOrFailureReason
return $list
}
function format-output{
param(
[object]$list
)
$PKIDFormat = @{Expression={$_.PKID};Label="PackageID";width=12}
$ProgramFormat = @{Expression={$_._ProgramID};Label="Program";width=45}
$StateFormat = @{Expression={$_._State};Label="State";width=10}
$StartFormat = @{Expression={$_._RunStartTime};Label="Start Time";width=20}
$ExitFormat = @{Expression={$_.SuccessOrFailureCode};Label="Exit Code";width=9}
$ReasonFormat = @{Expression={$_._SuccessOrFailureReason};Label="Reason"}
$list | Format-Table $PKIDFormat,$ProgramFormat,$StateFormat,$StartFormat,$ExitFormat,$ReasonFormat
}
$list = get-64bit
format-output $list