Skip to content

Instantly share code, notes, and snippets.

@SMSAgentSoftware
Created May 15, 2018 15:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SMSAgentSoftware/baae4679a71c5661a4ac2d0dbcfc1c7a to your computer and use it in GitHub Desktop.
Save SMSAgentSoftware/baae4679a71c5661a4ac2d0dbcfc1c7a to your computer and use it in GitHub Desktop.
PowerShell wrapper to run Microsoft's SetupDiag utility for troubleshooting Windows 10 setup. For use in an SCCM task sequence.
# Script to run SetupDiag to troubleshoot Windows 10 Setup
# Download SetupDiag.exe from https://go.microsoft.com/fwlink/?linkid=870142 and place in same directory as this script
# Get the CCM Logs location from registry
$LogLocation = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\CCM\Logging\@Global" -Name LogDirectory | Select -ExpandProperty LogDirectory
#$LogLocation = "$env:SystemRoot\CCM\Logs"
# Get the location we're running from (or use $PSScriptRoot)
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path -Parent
# Check that .Net 4.6 minimum is installed
If (Get-ChildItem "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" | Get-ItemPropertyValue -Name Release | ForEach-Object { $_ -ge 393295 })
{
Try
{
Start-Process -FilePath "$ScriptPath\SetupDiag.exe" -ArgumentList "/Output:$LogLocation\SetupDiagResults.log" -Wait -ErrorAction Stop
}
Catch
{
"[ERROR] There was an error starting SetupDiag.exe: $_" | Out-file -FilePath "$LogLocation\SetupDiagResults.log" -Force
}
}
Else
{
"[ERROR] .Net Framework 4.6 is required to run SetupDiag.exe" | Out-file -FilePath "$LogLocation\SetupDiagResults.log" -Force
}
@cwmoriarty
Copy link

I am not seeing "/ZipLogs:True" as would be expected in your blog post.

Perhaps this would help:

Start-Process -FilePath "$ScriptPath\SetupDiag.exe" -ArgumentList "/Output:$LogLocation\SetupDiagResults.log /ZipLogs:True" -Wait -ErrorAction Stop
Copy-Item "$ScriptPath*.zip" -Destination $LogLocation

@SMSAgentSoftware
Copy link
Author

It creates the Logs.zip file even without that switch.

@cwmoriarty
Copy link

It creates the Logs.zip file even without that switch.

I see that now. Still very helpful to copy that to $logLocation.
This script is awesome. I use it as part of an upgrade TS that will copy setup error logs to a network share for inspection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment