Click on Pictures to View

To view a larger version of an image within a post, just click on the picture you want to view :)
Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Tuesday, November 27, 2018

Comparing AD Group Member Count & SCCM Collection Membership


Recently there was some concern that our SCCM 2012 R2 collections that referenced/queried Active Directory security groups weren't updating or syncing properly.

A simple way I wanted to confirm if this was the case, was to compare the number of assets in a particular AD group with its corresponding SCCM collection.

After some quick research, I discovered a relatively easy PowerShell method to count the number of members in the Active Directory group.


I opened an elevated Powershell window (aka, right-click & Run As Admin...) and ran the following:

PS C:\Windows\system32>  $users = Get-ADGroupMember -Identity 'ADGroupName'
PS C:\Windows\system32>  $users.Count
160
PS C:\Windows\system32>  $users |Export-Csv -path C:\temp\psexport.csv



The first line sets the $users variable.
The second line returns the member count.
The third line exports the members & info as a CSV to the path specified.


So I got the count of members in the AD group, which was 160, and went ahead and exported the information to a CSV file to open within Excel.

Next, I opened the SCCM collection to show the members (can also right click the collection name and click Show Members).  The collection was showing a count of 106 members in the collection information.

On the device membership list screen, do Ctrl + A to select all members, then Ctrl + C to copy the list.
Last, paste the copied data into Excel.


Finally, I used the "Ablebits Data Merge Two Tables" wizard tool to compare the two excel spreadsheets using the computer name as the key.

I had the SCCM info as the main table, and the AD info as the lookup table.



Using the tool's result column (MTW Status), I looked for all non-matching entries - i.e. entries that are in AD group that are not in the SCCM collection.

I found 54 assets that are in the AD group but do not show up in the SCCM collection.  In fact, these assets did not appear to be in SCCM at all.

Further investigation revealed these computers to be dead accounts in Active Directory, so they were inactive altogether and could actually be deleted from Active Directory since they were either disposed or no longer on the domain, etc.

In the end, we proved that SCCM was updating its membership based on the active computer accounts in the AD security group, as expected.



Sources:


Computer in AD Not Appearing in SCCM:
https://social.technet.microsoft.com/Forums/en-US/5923a17c-3994-4bd0-8811-ce2f2e8593f0/computer-in-ad-not-appearing-in-sccm?forum=configmanagerdeployment


How To Export a Collection to CSV in SCCM 2012:
https://community.spiceworks.com/topic/259637-how-to-export-a-collection-to-csv-in-sccm-2012


Powershell Count Members of an AD Group:
http://blogs.microsoft.co.il/skepper/2016/05/31/powershell-count-members-of-a-ad-group/


Ablebits Data Merge Two Tables in Excel Tool:
https://www.ablebits.com/excel-lookup-tables/index.php



Thursday, January 4, 2018

Windows 10 Will Not Update / Check for Update Fails

Updated Steps 4/12/2018 to include workaround of error: WARNING: Can't find registered service Microsoft Update. Use Get-WUServiceManager to get registered service.



****If you are having difficulty with Windows 10 downloading updates or being stuck at 0% check out my other post here: http://austecjenni.blogspot.com/2017/07/windows-10-updates-wont-download.html****

The Problem:

My Windows 10 laptop seemed unable to successfully check for updates, let alone download and install them.

I just kept getting a generic "There were some problems..." message with error code 0x80244022.


The error code did not prove helpful upon my research of it, but I recalled a Powershell method I used in the past to force windows to update on Windows Server 2012, so I looked for a similar approach for Windows 10.


Steps for Resolution:

1) Download the latest version of PSWindowsUpdate.zip from Technet (https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/)

2) After downloading, extract the contents of the zip file to:
             C:\Windows\System32\WindowsPowerShell\v1.0\Modules\

3)  Click Continue if a UAC prompt pops up

4)  Open an elevated PowerShell window
     (Search for Windows Powershell, right click and Run As Administrator)

5)  Type the following and then press enter:
       Set-ExecutionPolicy RemoteSigned

6)  Confirm the change of the execution policy by pressing Y and then Enter

7)  Type the following and then press enter:
      Import-Module PSWindowsUpdate

8)  Type the following and then press enter to apply Windows Updates:
      Get-WUInstall -WindowsUpdate

8)  Type the following and press enter to get the WUServiceManager services list:
       Get-WUServiceManager


Example (notice there is only Windows Update service available):


9)  Next type the following and press enter to add the Microsoft Update Service:
      Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false



Example (see the Microsoft Updates service is now in the list)





(Or, alternatively, type Add-WUServiceManager, enter the
ServiceID: 7971f918-a847-4430-9279-4a52d1efe18d when prompted, and press enter to confirm)



10)  Display a list of available updates from the Microsoft Update servers by typing the following and then press enter:
       Get-WUInstall -MicrosoftUpdate -ListOnly

11)  Install the available updates by typing the following and then press enter:
        Get-WUInstall -MicrosoftUpdate -IgnoreUserInput -AcceptAll -IgnoreReboot -Verbose

12) Reboot the machine and repeat as necessary until there are no more available and relevant updates displayed when running the -ListOnly command and Windows Update in Settings shows as Up to Date

You can also double check by choosing "Check online for updates from Microsoft Update" and see if it returns anything.  I did not have that option to begin, but it showed up after my machine was finally updated via this method.



Sources:

Managing Windows Updates with PowerShell:
https://www.petri.com/manage-windows-updates-with-powershell-module

Windows Update PowerShell Module (TechNet):
https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/

Update and Upgrade Windows 10 using PowerShell:
https://www.tenforums.com/tutorials/76207-update-upgrade-windows-10-using-powershell.html

Powershell for Automatize Windows Update and Program Installation:
https://www.windowsbbs.com/threads/powershell-for-automatize-windows-update-and-program-installation.110303/

Friday, July 21, 2017

Windows 10 Updates Won't Download

I was having an issue where my Windows 10 machine wouldn't download updates.  It was stuck at 0%.  Other previous updates I noticed failed to install altogether as well.

I tried installing them via PowerShell (see resources links at bottom for method) to no avail, it would just get stuck downloading in the PS session.

Came across an article that had a solution.  Here's the rundown of what worked for me from it (supposedly should work for Windows stuck at downloading at any point - see link to original article also at the bottom)

1.  Open a elevated command prompt (right click cmd.exe and run as admin)

2.  Enter the following two commands one at a time:

                      net stop wuauserv
                      net stop bits         

3.  Browse to C:\Windows\SoftwareDistribution folder; delete or move all folders and files inside to a desktop folder if you are cautious about deleting...

4.  Type in the elevated command prompt the following two commands, one at a time:
                       net start wuauserv
                        net start bits

5.  Run Windows Update again - the updates should download and install successfully.

6.  Restart to complete the update process.

update 3/3/2023 I believe this process also works in the context of Windows Server 2012 or other with the correct update package and path.



SOURCES:

"Windows Update stuck downloading updates in Windows 10" - http://www.thewindowsclub.com/windows-update-stuck-downloading-updates

"Update and Upgrade Windows 10 using powershell" - 

Wednesday, October 7, 2015

Find Product GUID w/ WMIC or Powershell, & Other Useful Commands

Occasionally one needs to know what software is installed and its associated GUID.

There are a few simple ways to acquire this information for .msi's without going line by line through the Uninstall key in the Registry.

First there is the basic wmic method in a command prompt:

wmic product get

This will output a lot of information that is generally hard to look at, but nonetheless shows you the installed programs and their GUIDs if you can muddle your way through it (or output the results to a text file and search from there, which is discussed below)

Second you can simply call only application names and search for the product there, and then run a second command to find its specific GUID.

1) wmic product get name
2) wmic product where name="APPNAME" get Name,Version,IdentifyingNumber

Insert the application name acquired from step one where it says APPNAME (keep the quotes) in step two.


For any of the above commands, you can output them to a text file and or run them for a remote computer on the network.

Output to Text file named InstalledPrograms on C:
wmic product get name > C:\InstalledPrograms.txt

Run wmic command for a remote computer:
wmic /node:COMPUTERNAME {rest of command here}

Replace COMPUTERNAME with the hostname of the machine you want the results from.  Don't remove the /node: part.

Here's a neat trick using Powershell to get the information with output in a neat little table.  In powershell, run:

get-wmiobject -class Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage

To do the same only for a remote computer:

get-wmiobject - class Win32_Product -computername COMPUTERNAME | Format-Table IdentifyingNumber, Name, LocalPackage

Replace COMPUTERNAME with the hostname of the machine you want the results from.

This line will return all the subkeys and their registry values for the Uninstall registry key.


Get-ChildItem hklm:\software\Wow6432Node\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath}


Other random but useful commands are listed below.

To get hardware information on a remote system (replace COMPUTERNAME w/ hostname):

systeminfo /s COMPUTERNAME

To see the currently logged on user of a remote system (replace COMPUTERNAME w/ hostname):

wmic /node:COMPUTERNAME ComputerSystem Get Username

To get the IP address of a remote system (replace COMPUTERNAME w/ hostname)

wmic /node:COMPUTERNAME nicconfig get ippaddress

FYI - here are the Uninstall reg key locations:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\CurrentVersion\Uninstall

***Many of these commands can take some time especially if done for a remote machine or if there are a lot of applications in question.  You may want to go get a cup of coffee after pressing enter and when you get back you'll have the information you need :) ***


Resources:

http://www.computerhope.com/wmic.htm

http://software-inventory.net/installed-software-audit

https://technet.microsoft.com/en-us/library/dd347651.aspx

http://stackoverflow.com/questions/29937568/how-can-i-find-the-product-guid-of-an-installed-msi-setup

http://betanews.com/2011/01/14/wmic-the-best-command-line-tool-you-ve-never-used/

http://blogs.technet.com/b/askperf/archive/2012/02/17/useful-wmic-queries.aspx

https://technet.microsoft.com/en-us/library/ee176852.aspx