I know this is an old thread but I recently had to do this and found that the following Powershell commands to be very useful. They only get the constraints that I needed but you can make mnor mods to add any other constraints or even objects that you want.
$sql.Databases["MyDB"].Tables | % {$_.Indexes} | % {$_.script() }
$sql.Databases["MyDB"].Tables | % {$_.ForeignKeys} | % {$_.script()}
$sql.Databases["MyDB"].Tables | % {$_.Columns} | ? {$_.DefaultConstraint -ne $null} | % {$_.DefaultConstraint.script()}
Of course you will need to load the the SMO object and connect to the server:
$smo = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')
$sql = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "YourServer"
These commands will output to the screen. If you want to dump the results to a file just add the following to the end of the commands above:
| Out-File -FilePath "C:\YourPath\ScriptFilename.sql"