I was wondering if another set of eyes can spot where I'm going wrong. I'm trying to add am exceptions.sites file to a users Java folder via GPO so as to allow for Edge Compatibility mode to work without user intervention. We have a lot of legacy applications and a lot of users so automating this would be great.
The script seems to run without error.
$Source = '\\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites'
$users = (Get-ChildItem 'c:\Users\').name
$JavaFolder = "C:\Program Files\Java\"
$isJava = $false
$SEL = "Select string"
$DAFMComputer = "ControlPC"
#Do PC check to apply to only one PC
if ($DAFMComputer -like "ControlPC")
{
if (JavaPath -Path $JavaFolder) #if Java is installed
{
Foreach ($user in $users)
{
if (FileExists -Path "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites") #check for the file
{
$SEL = Select-String -Path "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" -Pattern https://agapps.agriculture.gov.ie #Check for the string pattern
if ($SEL -ne $null)
{
#do nothing as the exception file exists with the URL we need do nothing
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\AlreadyThere\"
}
else
{
#add the following lines.
Add-Content "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" "`nhttps://app.company.com/"
Add-Content "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" "`nhttps://app.company.com/"
Add-Content "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" "`We are adding lines"
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\FileExistsAddlines\"
}
}
else #file does not exist
{
Copy-Item -Path $Source -Destination "c:\Users\$user\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" -force
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\Filecopy\"
}
}
} # end file copy.
else
{
#No Java Do nothing
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\NoJavaDoNothing\"
}
else
{
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\NoComputerMatch\"
#do nothing as the PC name does not match
}
}
#Control line showing the script runs.
Copy-Item -Path \\thepath\Policies\{1FA921CE-231E-4982-8EBA-29E3AD4A44EF}\Machine\Scripts\Startup\exception.sites -Destination "c:\Temp\Running\"
The only line that reliably runs is the last control line on line 55 which copies a file to a folder. I've used similar copy file indicators in the if else loops to track and see where the loop is. But none of these are ever populated.
It's all the if elses are evaluating to false and no matter what i can't get it to enter the loop.
Any suggestions / pointers would be welcome
Thanks John