Menu
CCMEXEC.COM – Enterprise Mobility
  • Home
  • General
  • Configuration Manager
  • Windows 10
  • Windows 11
  • Intune
  • GitHub
  • About
CCMEXEC.COM – Enterprise Mobility

Powershell script to collect sccm log files from clients using Run Script

Posted on October 27, 2017October 27, 2017 by Jörgen Nilsson

During my session at Techdays Sweden I demoed the new Run Script feature both in Configuration Manager 1706 and the enhancements made in the Technical preview after and showed how a variable can be used.

In the first demo I used the below Powershell script sample that will collect all SCCM Client log files in a Zip archive and copy them to a file share in a folder with the name of the computer the log files are from.

This could be one scenario to use with the new Run Script feature. The scripts are run almost instantly on the clients, one thing to note is that if the client isn’t online it has 1 hour to come online and run it otherwise it will not run.

Example one without parameters in Configuration Manager 1706:

When the script is run which we can track under script status.

And we have a new file in a new folder with the log files from the client.

If we do the same in the Technical Preview that supports variables we can remove the hard coded share name and use a variable instead.

We can then add a default value for the parameter in this case the logshare to be used.

And when we run the script we can change the sharename for where the log files should be copied.

The new parameter feature is great! Someone asked for the script I used and here it is.

$Logshare = "\\cmtp4\logs"
#Get path for SCCM client Log files
$Logpath = Get-ItemProperty -path HKLM:\Software\Microsoft\CCM\Logging\@Global
$Log = $logpath.LogDirectory

#Create folders
New-Item -Path $env:temp\SCCMLogs -ItemType Directory -Force
Copy-item -path $log\* -destination $env:temp\Sccmlogs -Force

#Create a .zip archive with sccm logs
Compress-Archive -Path $env:temp\Sccmlogs\* -CompressionLevel Optimal -DestinationPath $env:temp\sccmlogs

#Copy zipped logfile to servershare
$Computerlogshare=$logshare + “\” + $env:Computername
Write-host $Computerlogshare
New-Item -Path $Computerlogshare -ItemType Directory -Force
Copy-Item $env:temp\sccmlogs.zip -Destination $Computerlogshare -force

#Cleanup temporary files/folders
Remove-Item $env:temp\SCCMlogs -Recurse
Remove-item $env:temp\SCCMlogs.zip

In the Technical preview release we can also use Parameters with our script so I changed it so it asks for the $Logshare variable when executed in the console as shown below.

 

The only thing that is modified in the script to the version using variables is this line:

$logshare = "\\Server1\Logs\"

Which is replaced by

Param(

[string]$Logshare

) #end param

3 thoughts on “Powershell script to collect sccm log files from clients using Run Script”

  1. Ram Lan says:
    February 5, 2018 at 7:30 pm

    For some reason, I don’t see the logs after running the script. The script ran successfully. The only thing, I changed in the script is server name and folder where to save the logs. Yet there is nothing. Not sure what, I am missing.
    Script is approved and executed successfully.

    Reply
    1. Giovanni Perini says:
      July 18, 2018 at 2:10 pm

      I think that it is a right issue. Since the script will be run under the local system account of the targeted system that system needs to have modify share and NTFS rights on the share you specify. Best is to punt the systems in a AD group and give this group the required rights.

      Reply
  2. Johnny says:
    June 6, 2019 at 4:04 am

    If it’s in the lab, you can also give “Everyone” permissions. Thank you for this great script!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

My name is Jörgen Nilsson and I work as a Senior Consultant at Onevinn in Malmö, Sweden. This is my blog where I will share tips and stuff for my own and everyone elses use on Enterprise Mobility and Windows related topics.
All code is provided "AS-IS" with no warranties.

Recent Posts

  • New settings in Intune Security Baseline Windows 11 24H2 -2504
  • Managing extensions in Visual Studio Code
  • Reinstall a required Win32app using remediation on demand
  • Administrator protection in Windows 11 – First look
  • Remediation on demand script – ResetWindowsUpdate
©2025 CCMEXEC.COM – Enterprise Mobility | WordPress Theme by Superb Themes
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT