Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@cwmoriarty cwmoriarty commented Jun 12, 2019

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

@cwmoriarty

This comment has been minimized.

Copy link

@cwmoriarty cwmoriarty commented Jun 12, 2019

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

This comment has been minimized.

Copy link
Owner Author

@SMSAgentSoftware SMSAgentSoftware commented Jun 12, 2019

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

@cwmoriarty

This comment has been minimized.

Copy link

@cwmoriarty cwmoriarty commented Jun 12, 2019

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
You can’t perform that action at this time.