ConfigMgr Run Script: Collect Logs

Microsoft introduced the Run Script feature way back in ConfigMgr 1706. This feature allows a ConfigMgr administrator to execute a PowerShell script on a system. For a complete review of this feature, see our blog post here: ConfigMgr 1706: Run Script – (windowsmanagementexperts.com)

I recently wrote a script that will copy or export a host of interesting logs to a file share. This can be helpful in troubleshooting device issues, or just gathering logs for any purpose that you may find. I’ll go through setting up the file share, and provide details as to what the script captures. The script is available for download at the bottom.

Creating the File Share

First, we must set up a file share to copy the logs too. I suggest creating a share (it can be on any Windows server) and giving your Domain Computers group write access only. Because the script executes as the system account, it will perform the copy as the computer’s computer object. By granting write access only, you prevent other computer objects or users from accessing these files. You will of course have to grant yourself, or a group of users read access to be able to retrieve the files.

I would suggest making this a hidden share.

Script

The script itself is pretty simple, and you can add to it if you want. It will copy the files into a folder that is formatted like <computer name>-<date>. Just change the first part of line 2 to reflect the file share.

The script currently performs these actions:

  • Copies the entire SCCM client log directory (normally C:\Windows\CCM\Logs)
  • Copies the Windows Update log.
    • Pre-Windows 10, it grabs C:\Windows\WindowsUpdate.log
    • For Windows 10, it runs the Get-WindowsUpdateLog PowerShell cmdlet and outputs the result to the file share
  • Exports the System, Application, BitLocker, KMS, MBAM, and Windows Defender event logs
  • It runs section 3 of this script: https://blogs.msdn.microsoft.com/rkramesh/2016/09/19/sccm-client-log-collection-for-troubleshooting/, which gathers various details about the client

Happy Scripting!

Disclaimer
All content provided on this blog is for information purposes only. Windows Management Experts, Inc makes no representation as to accuracy or completeness of any information on this site. Windows Management Experts, Inc will not be liable for any errors or omission in this information nor for the availability of this information. It is highly recommended that you consult one of our technical consultants, should you need any further assistance.

Share:

Facebook
Twitter
LinkedIn

Contact Us

On Key

More Posts

Mastering Azure AD Connect - A Comprehensive Guide by WME
Active Directory

Mastering Azure AD Connect – A Comprehensive Guide

Modern businesses are fast moving toward cloud-based infrastructure. In fact, cloud-based business is not just a trend anymore but a strategic necessity. Microsoft’s Azure Active Directory (Azure AD) has become a frontrunner in this domain. It

Read More »
Security Best Practices in SharePoint
Office 365

Security Best Practices in SharePoint

Microsoft SharePoint is an online collaboration platform that integrates with Microsoft Office. You can use it to store, organize, share, and access information online. SharePoint enables collaboration and content management and ultimately allows your teams to

Read More »
The Ultimate Guide to Microsoft Intune - Article by WME
Active Directory

The Ultimate Guide to Microsoft Intune

The corporate world is evolving fast. And with that, mobile devices are spreading everywhere. As we venture into the year 2024, they have already claimed a substantial 55% share of the total corporate device ecosystem. You

Read More »
Protecting Microsoft 365 from on-Premises Attacks
Cloud Security

How to Protect Microsoft 365 from On-Premises Attacks?

Microsoft 365 is diverse enough to enrich the capabilities of many types of private businesses. It complements users, applications, networks, devices, and whatnot. However, Microsoft 365 cybersecurity is often compromised and there are countless ways that

Read More »
Be assured of everything

Get WME Services

Stay ahead of the competition with our Professional IT offerings.