Skip to content

Commit

Permalink
Changed to Get-CimInstance where it can be done
Browse files Browse the repository at this point in the history
  • Loading branch information
GAJ-san committed Oct 20, 2023
1 parent ec348ec commit 4f8afd7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Winget-AutoUpdate/Winget-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $LogFile = "$WorkingDir\logs\updates.log"

if ($IsSystem) {
#Check if any connected user when running as system
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
$explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
#Check if ServiceUI exists
$ServiceUI = Test-Path "$WorkingDir\ServiceUI.exe"
If ($explorerprocesses.Count -gt 0 -and $ServiceUI) {
Expand Down Expand Up @@ -349,8 +349,7 @@ if (Test-Network) {
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
}

#User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
$explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
If ($explorerprocesses.Count -eq 0) {
Write-ToLog "No explorer process found / Nobody interactively logged on..."
}
Expand Down
2 changes: 1 addition & 1 deletion Winget-AutoUpdate/functions/Test-PendingReboot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Test-PendingReboot {
if (($WMI_Reg.EnumKey($HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootPending') { $PendingReboot = $true }
if (($WMI_Reg.EnumKey($HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")).sNames -contains 'RebootRequired') { $PendingReboot = $true }

#Checking for SCCM namespace
#Checking for SCCM namespace (can't get it done with Get-CimInstance, using deprecated Get-WmiObject)
$SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
if ($SCCM_Namespace) {
if (([WmiClass]"\\$Computer\ROOT\CCM\ClientSDK:CCM_ClientUtilities").DetermineIfRebootPending().RebootPending -eq $true) { $PendingReboot = $true }
Expand Down
1 change: 1 addition & 0 deletions Winget-AutoUpdate/functions/Update-StoreApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Function Update-StoreApps {
Write-ToLog $force_string "yellow"

try {
# Can't get it done with Get-CimInstance, using deprecated Get-WmiObject
$namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_EnterpriseModernAppManagement_AppManagement01"
$wmiObj = Get-WmiObject -Namespace $namespaceName -Class $className
Expand Down

0 comments on commit 4f8afd7

Please sign in to comment.