You can dynamically build $outputPath in PowerShell by combining a hardcoded directory, the system’s computer name, and the current date in the format you want. You don’t need extra quotes inside the string unless you are trying to escape something, PowerShell handles variable expansion inside double quotes. For your example, it would look like this:
$directory = "C:\Temp"
$computerName = $env:COMPUTERNAME
$date = Get-Date -Format "yyyyMMdd"
$outputPath = "$directory\$computerName`_$date.reg"
Here, $env:COMPUTERNAME retrieves the computer name from the system, Get-Date -Format "yyyyMMdd" gives the date in the format 20251222, and the backtick before _ is optional but can prevent ambiguity if needed. This will produce something like C:\Temp\GSINKINSON_20251222.reg.
Then your export part can use $outputPath directly:
Write-Host "Exporting registry."
Start-Process -FilePath "regedit.exe" -ArgumentList "/E", "$outputPath" -Wait -NoNewWindow
Write-Host "Registry export complete."
This avoids double quotes inside quotes, which can confuse PowerShell, and ensures the path is built dynamically for any system and date.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin