Q:

Update Java Exception List

I need to add URL to Java exception sites. I found a way to add using powershell but i need to add only if the url is not yet added.
i tried the following code below. but it always adds. i need to add the URL only if it does not exist.
$site = "somesite.com"
Add-Content -Path "$env:USERPROFILE\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" -Value "$site"

the specified URL is added only if it does not exist in the list already

A:

$javafile = "$env:USERPROFILE\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites"
$site = 'somesite.com'
if (! (select-string -quiet $site $javafile)) {
  Add-Content $javafile $site
}

Note that using >> or out-file would encode the line in unicode and break it.

