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
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.
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.
If it’s in the lab, you can also give “Everyone” permissions. Thank you for this great script!