Windows – Appending deployment.properties to enable TLS

javapowershellscriptingwindows

I need to be able to append everyone's deployment.properties file to add additional lines to enable all versions of TLS. Big enterprise uses multiple different versions of Java and also multiple different departments use different exceptions. I have attempted to append the file using powershell but it inserts line spaces between each letter.

this is the only PS script i found that is able to insert into the file.

echo "`r`n deployment.security.SSLv3=true" >> "c:\users\%userprofile%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties"

notice it enters it after the last line and wont let me return down

Here is the code i need to insert

# Advanced Security Settings\Use TLS 1.0
deployment.security.TLSv1=true
deployment.security.TLSv1.locked
# Advanced Security Settings\Use TLS 1.1
deployment.security.TLSv1.1=false
deployment.security.TLSv1.1.locked
# Advanced Security Settings\Use TLS 1.2
deployment.security.TLSv1.2=false
deployment.security.TLSv1.2.locked
# Miscellaneous\Place Java icon in system tray
# Miscellaneous\Java Quick Starter
deployment.system.tray.icon=false
deployment.system.tray.icon.locked

I just need to know how I can do it via a script or powershell for the entire enterprise. with out replacing the original deployment.properties file and with proper formatting.
Thanks guys!

Best Answer

The $env:userprofile\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" file has (presumably) ANSI (or UTF-8) encoding.

On the other hand, about_Redirection help topic says:

… When you are writing to files, the redirection operators use Unicode encoding. If the file has a different encoding, the output might not be formatted correctly…

To redirect content to non-Unicode files, use the Out-File or Add-Content cmdlet with its Encoding parameter. For instance, something like

$CodeToInsert = @'
# Advanced Security Settings\Use TLS 1.0
deployment.security.TLSv1=true
deployment.security.TLSv1.locked
# Advanced Security Settings\Use TLS 1.1
deployment.security.TLSv1.1=false
deployment.security.TLSv1.1.locked
# Advanced Security Settings\Use TLS 1.2
deployment.security.TLSv1.2=false
deployment.security.TLSv1.2.locked
# Miscellaneous\Place Java icon in system tray
# Miscellaneous\Java Quick Starter
deployment.system.tray.icon=false
deployment.system.tray.icon.locked
'@
$FilePath = "$env:USERPROFILE\AppData\LocalLow\Sun\Java\Deployment\deployment.properties"

Add-Content -Path $FilePath -Value $CodeToInsert -Encoding default

See also

Note: you can query the file.encoding property or Charset.defaultCharset() to find the current default encoding in Java.

For the entire enterprise, you could configure above script to Run Once on user logon.