
Creating SCCM User and Device Collections based on Active Directory Groups
Create a User Collection and a Device Collection that pulls its members from an active directory group 1. Make sure you have Discovery set up on your Active Directory or Specific OU containing groups. You can do this by clicking Administration > Discover Methods then right click on “Active Directory Group Discovery” and choose Properties. […]
C# convert WMI DateTime to standard DateTime
WMI Dates and times are in DMTF datetime format. The following is the command to convert a given DMTF datetime to DateTime.
1 |
DateTime Date = ManagementDateTimeConverter.ToDateTime(WMIDate); |
Microsoft Documentation
Configuration Manager 2012 how to add users in an AD group to a user collection
In SCCM the below query string can be used to populate a user collection based on AD group.
1 |
select * from SMS_R_User where SMS_R_User.SecurityGroupName = "DOMAIN\\User_Group” |
Powershell and VB script to update a registry key if it exists on the local system
Here are a couple scripts I wrote to update a registry key on a system if it the key exists. I created a PowerShell script to do this then realized that some of the systems being updated were pretty old so decided to go with VB Script Power Shell Script
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 |
$keypath = "HKLM:\SOFTWARE\SomeSoftware\Key" $keypath32 = "HKLM:\SOFTWARE\Wow6432Node\SomeSoftware\Key" $regkey = "key" $keyvalue = "keyValue" Push-Location if(Test-Path $keypath) { Set-Location $keypath Set-ItemProperty .$regkey $keyvalue if(Test-Path $keypath32) { Set-Location $keypath32 Set-ItemProperty .$regkey $keyvalue } } elseif(Test-Path $keypath32) { Set-Location $keypath32 Set-ItemProperty .$regkey $keyvalue } Pop-Location exit 0 |
VB Script
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 |
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT Const HKCU = &H80000001 'HKEY_CURRENT_USER Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Const HKUS = &H80000003 'HKEY_USERS Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG RegkeyPath = "SOFTWARE\SomeSoftware\Key" RegkeyPath32 = "SOFTWARE\Wow6432Node\SomeSoftware\Key" RegKey = "Key" keyvalue = "KeyValue" Function KeyExists(Key, KeyPath) Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv") If oReg.EnumKey(Key, KeyPath, arrSubKeys) = 0 Then KeyExists = True Else KeyExists = False End If End Function Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv") if KeyExists(HKLM, RegkeyPath) = True Then if KeyExists(HKLM, RegkeyPath32) = True Then oReg.SetStringValue HKLM, RegKeyPath32, RegKey, keyvalue end if oReg.SetStringValue HKLM, RegKeyPath, RegKey, keyvalue elseif KeyExists(HKLM, RegKeyPath32) = True Then oReg.SetStringValue HKLM, RegKeyPath32, RegKey, keyvalue else end if |
[…]
Powershell Script to detect one or more KB articles are installed
This PowerShell script checks OS version or KB articles are installed on system. Used in SCCM as a detection method for IE 11 Prereqs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$osresult = $null $os = (Get-WmiObject Win32_OperatingSystem).Name if ($os -like "*Windows 8*") {$osresult = "True"} elseif ($os -like "*Server 2012*") {$osresult = "True"} else{ $osresult = get-hotfix -id KB2670838,KB2729094,KB2786081,KB2834140 -ea 0 if ($osresult -like "*KB2670838*" -and $osresult -like "*KB2729094*" -and $osresult -like "*KB2786081*" -and $osresult -like "*KB2834140*"){ $osresult = "True" } else { $osresult = $null } } $osresult |
Powershell Install multiple Windows Updates .MSU
This script will loop through multiple msu windows updates files and install them.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
############################################## # # Name: PrereqInstaller.ps1 # Version: v0.1 # Date: 3/13/2014 # Purpose: Install multiple Microsoft KB#### *.msu # Author: Randy Gray # # # Folder Structure # # source # ├-- PrereqInstaller.ps1 # ├-- Win7 # | ├-- x64 # | | | KBxxxxxxa # | | | └ Windows6.1-KBxxxxxxx-x64.msu # | | └ KBxxxxxxb # | | └ Windows6.1-KBxxxxxxx-x64.msu # | └-- x86 # | └ Windows6.1-KBxxxxxxx-x86.msu # └-- Win81 # ├-- x64 # | └ KBxxxxxxx # | └ Windows8.1-KBxxxxxxx-x64.msu # └-- x86 # └ Windows8.1-KBxxxxxxx-x86.msu # # # Variables # $path - directy scritpt was run from. # $msus - array of windows updates # $msu - current windows udpate # $update - array of file name spilt by '-' # $kbart - current update KB name # $Hotfix - result returned during installed check # $command - command to install update # $parameters - command plus the parameters to the install command '\quiet \norestart' # $install - process to start installation # $OS - Current OS version # #folder - current folder of under path that contains the udpates. # ############################################### function Install-MSU($path) { # get updates in folders $msus = ls -Path $path *.msu -Recurse # loop through updates foreach ($msu in $msus) { # spilt file name to get KB artical number $update = $msu.Name -Split'-' $kbart = $update[1] # check if update is already installed $HotFix = Get-HotFix -id $kbart -ea 0 # run if update is not installed if($HotFix -eq $null) { Write-Host "Installing $kbart" $command = "`"" + "$path\$msu" + "`"" $parameters = $command + "\quiet \norestart" $install = [System.Diagnostics.Process]::Start( "wusa",$parameters ) $install.WaitForExit() } # run if update is installed else { Write-Host "Update $kbart installed" } } } # set $path to current directory location $path = get-location # set $OS to current OS $OS = gwmi -query "select Caption, OSArchitecture from win32_OperatingSystem" # if OS is windows 7 if($OS.Caption -match 'Windows 7') { if($OS.OSArchitecture -match '64-bit') { $folder = 'win7\x64' $path = "$path\$folder" Install-MSU($path) } else { $folder = "win7\x86" $path = "$path\$folder" Install-MSU($path) } } # if OS is windows 8.1 elseif($OS.Caption -match 'Windows 8.1') { if($OS.OSArchitecture -match '64-bit') { $folder = 'win81\x64' $path = "$path\$folder" Install-MSU($path) } else { $folder = "win81\x86" $path = "$path\$folder" Install-MSU($path) } } else { } |