SCCM – PowerShell – SQL Query

email me

This is a SQL query written in PowerShell. It connects to the SCCM DB and returns Custom_Data for C and D drives.

#import-module sqlps
#Install-Module -Name SqlServer -AllowClobber
#Update-Module -Name SqlServer

Clear-Host

[string] $Server= "SCCM_Server\SQL_Instance"
[string] $Database = "CM_SITENAME"

# C Drive Query
[string] $SQLQuery1 = $("SELECT [Bitlocker_C_Drive00] FROM [dbo].[Custom_Custom_DATA] WHERE MachineID='$ResourceID'")

# D Drive Query
[string] $SQLQuery2 = $("SELECT [Bitlocker_D_Drive00] FROM [dbo].[Custom_Custom_DATA] WHERE MachineID='$ResourceID'")

# Not used at this time - no need to use this if connecting in authorized security context
#[string] $user = "username"
#[string] $pwd = "LetMeIn99$"

$Connection = New-Object System.Data.SQLClient.SQLConnection
$dt = new-object "System.Data.DataTable"

$Connection.ConnectionString = "server='$Server';database='$Database';trusted_connection=true;"
#$Connection.ConnectionString = "server='$Server';uid=$user;pwd=$pwd;database='$Database';trusted_connection=true;"
$Connection.Open()

# C Drive
$cmd1 = $Connection.CreateCommand()
$cmd1.CommandText = $SQLQuery1
$data1 = $cmd1.ExecuteReader()
$dt.Load($data1)
$CDrive = $dt | foreach { $_.Bitlocker_C_Drive00 }
$CDrive

# D Drive
$cmd2 = $Connection.CreateCommand()
$cmd2.CommandText = $SQLQuery2
$data2 = $cmd2.ExecuteReader()
$dt.Load($data2)
$DDrive = $dt | foreach { $_.Bitlocker_D_Drive00 }
$DDrive

# Close Connection
$Connection.Close()

Windows – Change Roaming Aggressiveness

email me

Batch

:: created to change the wireless roaming to medium-high

:: the class - not used, because it may change from model to model
:: {4d36e972-e325-11ce-bfc1-08002be10318}

:: setup
setlocal enabledelayedexpansion
set /a count=1

:: uses dynamic reg scanning to find the right class and subkey
for /f "tokens=1-4 delims= " %%a in ('reg query HKLM\SYSTEM\CurrentControlSet\Control\Class /v RoamAggressiveness /s') do (
:: sets the returned reg key 
if !count!==1 set var1=%%a
set /a count+=1
)

:: applies reg change
reg add "%var1%" /v RoamAggressiveness /t REG_SZ /d 3 /f

exit /b 0

 

PowerShell

Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -DisplayName "Roaming Aggressiveness" -DisplayValue "4. Medium-High"

Batch – Google Chrome Uninstall-Scrubber

email me

Methods for uninstalling Chrome

 

EXE (good)

"C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.140\Installer\setup.exe" --uninstall --multi-install --chrome --system-level --force-uninstall


WMI (meh)

wmic product where “name like ‘Google Chrome'” call uninstall /nointeractive


GUID

MSIEXEC.EXE /X{FE64921C-E29D-39EC-9DD9-C567C6E5A0C6} /qn /norestart

Note, GUIDs can be found

“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\”

“HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\”

 

Return any version number (better)

c:
cd\Program Files (x86)\Google\Chrome\Application

:: return version number
setlocal enabledelayedexpansion
set version=
set /a count=1
for /f “delims=” %%V in (‘dir “C:\Program Files (x86)\Google\Chrome\Application\” /a:d /b’) do (
if !count!==1 set version=%%V
set /a count+=1
)

“C:\Program Files (x86)\Google\Chrome\Application\%version%\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

:: those are are two hyphens in front of each parameter


Snapshot

As you see, this returns the version. Once you have that, it’s simple to plug that into the command to uninstall Chrome.

 

Notes

:: DEFAULT BROWSERS
“C:\Program Files (x86)\Google\Chrome\Application\63.0.3282.118\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\63.0.3282.132\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.119\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.140\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.167\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.168\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

“C:\Program Files (x86)\Google\Chrome\Application\64.0.3282.186\Installer\setup.exe” –uninstall –multi-install –chrome –system-level –force-uninstall

 

MsiExec.exe /X{141A8DCA-ECB5-3217-B35B-B7F562D65385} /qn /norestart

MsiExec.exe /X{D8BAA38A-97E1-3BD9-A877-673E81553618} /qn /norestart

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D8BAA38A-97E1-3BD9-A877-673E81553618}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{141A8DCA-ECB5-3217-B35B-B7F562D65385}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FE64921C-E29D-39EC-9DD9-C567C6E5A0C6}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{D8BAA38A-97E1-3BD9-A877-673E81553618}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{141A8DCA-ECB5-3217-B35B-B7F562D65385}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{FE64921C-E29D-39EC-9DD9-C567C6E5A0C6}” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome” /f

reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Google\Update” /f
reg delete “HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Update” /f

:: 63.0.3239.132
:: {141A8DCA-ECB5-3217-B35B-B7F562D65385}

:: 64.0.3239.140
{D8BAA38A-97E1-3BD9-A877-673E81553618}

:: 64.0.3239.119
{FE64921C-E29D-39EC-9DD9-C567C6E5A0C6}

————————————————————————-

:: 57 . 0 . 2987 . 133
:: {8AC8E2E9-87E7-30CA-8308-E737B3911CE5}

:: 58 . 0 . 3029 . 81
:: {A967B385-DA3A-32DD-B6F3-D169E888E661}

:: 58 . 0 . 3029 . 96
:: {A4690197-328E-3732-A460-124D6900D9C5}

:: 58 . 0 . 3029 . 110
:: {ED4B0482-0731-311E-80BB-7D1A87FDF296}

:: 59 . 0 . 3071 . 86
:: {98305915-759E-39B2-A385-5818CDBB9F5B}

:: 59 . 0 . 3071 . 104
:: {BDFAC210-BE15-32E6-BC3D-3CF0E7F4E430}

:: 59 . 0 . 3071 . 115
:: {715E251E-9134-3D1D-BE19-1C6EE18F8D24}

:: 60 . 0 . 3112 . 78
:: {3369F76A-F628-300A-8CC7-53CF96F12C56}

:: 60 . 0 . 3112 . 90
::{3369F76A-F628-300A-8CC7-53CF96F12C56}

:: 60 . 0 . 3112 . 101
:: {60C02A0E-51D2-3127-B4F1-2B92404692AF}

:: 60 . 0 . 3112 . 113
:: {4EC552DD-5454-3B12-A15F-D84ED8DD24D7}

:: 61 . 0 . 3163 . 91
:: {2170A876-572E-31E6-8E5E-157B5EEF508D}

Windows 10 – Application Settings Randomly Popping Up

email me

You’ll sometimes notice after upgrading to Windows 10, the settings, the enhanced application settings boxes, will just randomly appear. This is how you disable that odd behavior.

Run these commands from an admin command prompt, or add to a script:

net stop SysMain

sc config SysMain start= disabled

reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters” /v “EnableSuperfetch” /t REG_DWORD /d 0 /f