Forum Discussion
dcdiag crash with incorrect /s parameter
Hello,
I find a mistake in my script which cause DCDiag to crash :
dcdiag /v /c /d /e /s:%computername% > C:\Temp\dcdiag.txt
%computername% is the mistake. I replaced it by the real server name.
Seems like input it not enough checked.
Vincent
1 Reply
The issue is caused by using %computername% incorrectly with the /s parameter. The /s parameter expects a specific Domain Controller name (FQDN or NetBIOS), not a variable that may not resolve correctly in that execution context.
When %computername% does not resolve properly (for example in scheduled tasks, different shells, or remote execution), dcdiag may fail or crash because it cannot validate the target DC.
Solution:
Use a valid and resolvable Domain Controller name instead of %computername%, for example:
dcdiag /v /c /d /e /s:DC01.contoso.local > C:\Temp\dcdiag.txt
Alternatively, if you want to dynamically use the local machine name safely, use PowerShell instead of environment variables:
$dc = $env:COMPUTERNAME
dcdiag /v /c /d /e /s:$dc > C:\Temp\dcdiag.txt
Or simply run without /s if you are executing the command locally on a Domain Controller:
dcdiag /v /c /d /e > C:\Temp\dcdiag.txt
Summary:
/s parameter requires a properly resolvable DC name. Using %computername% can lead to failures depending on the execution context, so it’s safer to use a fixed DC name or PowerShell-based resolution.