Skip to content

Instantly share code, notes, and snippets.

@xoner
Created April 17, 2014 09:56

Revisions

  1. xoner created this gist Apr 17, 2014.
    45 changes: 45 additions & 0 deletions copy-java-security-options.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    $javaDeployment = ''
    $profilesDir = ''

    ## We are runnig Windows Vista, 7, 8 , Server 2008, 2008 R2, 2012 or highter
    if ([System.Environment]::OSVersion.Version.Major -ge 6)
    {
    Write-Host -ForegroundColor Green "OS Windows Vista, 7, 2008, 2008R2 or highter"
    $javaDeployment = 'AppData\LocalLow\Sun\Java\Deployment'
    $profilesDir = 'C:\Users'
    }
    # We are running Windows XP or server 2003 (spanish localized)
    elseif ([System.Environment]::OSVersion.Version.Major -eq 5)
    {
    Write-Host -ForegroundColor Green "OS Windows XP or 2003"
    $javaDeployment = 'Datos de Programa\Sun\Java\Deployment'
    $profilesDir = 'C:\Documents and Settings'
    }
    else
    {
    Write-Host -ForegroundColor Red "OS not supported"
    exit
    }

    $templFolder = [System.IO.Path]::Combine($env:USERPROFILE, $javaDeployment)

    foreach($item in (ls $profilesDir))
    {
    if($item.PSIsContainer)
    {
    $userDestDir = [System.IO.Path]::Combine($item.FullName, $javaDeployment);

    #echo $userDestDir;
    if ((Test-Path "$userDestDir") -and ($item.FullName -ne $env:USERPROFILE))
    {
    echo "$($item.FullName) has sun deployment";
    $configPathTmpl = $templFolder + '\deployment.properties'
    $urlExceptionPathTmpl = $templFolder + '\security\exception.sites';

    cp -Force $configPathTmpl $userDestDir
    cp -Force $urlExceptionPathTmpl $($userDestDir + '\security')
    echo ""
    echo ""
    }
    }
    }