Skip to content

Instantly share code, notes, and snippets.

@tsfahmed2
Created April 21, 2022 03:43
Show Gist options
  • Select an option

  • Save tsfahmed2/935b94a31dee1201fccf44397bba0995 to your computer and use it in GitHub Desktop.

Select an option

Save tsfahmed2/935b94a31dee1201fccf44397bba0995 to your computer and use it in GitHub Desktop.
<#
Install Zscaler
By me for XXXXX,
#>
Function Set-RegistryKey
{
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, HelpMessage = "Please Enter Registry Item Path", Position = 1)]
$Path,
[Parameter(Mandatory = $True, HelpMessage = "Please Enter Registry Item Name", Position = 2)]
$Name,
[Parameter(Mandatory = $True, HelpMessage = "Please Enter Registry Property Item Value", Position = 3)]
$Value,
[Parameter(Mandatory = $False, HelpMessage = "Please Enter Registry Property Type", Position = 4)]
$PropertyType = "DWORD"
)
# If path does not exist, create it
If ((Test-Path $Path) -eq $False)
{
$newItem = New-Item -Path $Path -Force
}
# Update registry value, create it if does not exist (DWORD is default)
$itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
If ($itemProperty -ne $null)
{
$itemProperty = Set-ItemProperty -Path $Path -Name $Name -Value $Value
}
Else
{
$itemProperty = New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType
}
}
function Install-MSIFile
{
[CmdletBinding()]
Param (
[parameter(mandatory = $true, ValueFromPipeline = $true, ValueFromPipelinebyPropertyName = $true)]
[ValidateNotNullorEmpty()]
[string]$msiFile,
[parameter()]
[ValidateNotNullorEmpty()]
[string]$targetDir
)
if (!(Test-Path $msiFile))
{
throw "Path to the MSI File $($msiFile) is invalid. Please supply a valid MSI file"
}
$arguments = @(
"/i"
"`"$msiFile`""
"/quiet"
"CLOUDNAME=zscalerbeta"
"DEVICETOKEN=888888888888888888888888888888888888888888888888888888888"
"POLICYTOKEN=88888888888888888888888888888888888888888888888888888888888"
"STRICTENFORCEMENT=1"
"REINSTALLDRIVER=1"
"USERDOMAIN=sample.com"
)
Write-Output "Arguments for this command line are $arguments"
if ($targetDir)
{
if (!(Test-Path $targetDir))
{
throw "Path to the Installation Directory $($targetDir) is invalid. Please supply a valid installation directory"
}
$arguments += "INSTALLDIR=`"$targetDir`""
}
Write-Output "Installing $msiFile....."
$process = Start-Process -FilePath msiexec.exe -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -eq 0)
{
Write-Output "$msiFile has been successfully installed"
Write-EventLog -Message "$msiFile has been successfully installed" -LogName System -Source EventLog -EventId 333
}
else
{
Write-Output "installer exit code $($process.ExitCode) for file $($msifile)"
Write-EventLog -Message "Zscaler Installer Error" -LogName System -Source EventLog -EventId 333
}
}
#######################
Write-EventLog -Message 'Zscaler install task : Begin running zscaler install on reboot' -LogName System -Source EventLog -EventId 333
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 1
#exit 1
#Install zscaler with strict enforcement and launch it
try {
$msifile = 'Zscaler-windows-3.7.2.18-installer-x64.msi'
$link = "https://d32a6ru7mhaq0c.cloudfront.net/Zscaler-windows-3.7.2.18-installer-x64.msi"
$tmp = "$env:TEMP\$msifile"
$client = New-Object System.Net.WebClient
$client.DownloadFile($link, $tmp)
if (Test-Path $tmp)
{
Write-Host "MSI file downloaded to $env:TEMP"
$tmp | Install-MSIFile -Verbose
Start-Sleep -Seconds 15
}
Write-EventLog -Message 'Completed install of zscaler with strictenforcement' -LogName System -Source EventLog -EventId 333
Write-EventLog -Message 'Zscaler install task : hi I ran on reboot' -LogName System -Source EventLog -EventId 333
# "schtasks.exe /delete /f /tn Install-Zscaleronfirstreboot"
Unregister-ScheduledTask -TaskName Install-Zscaleronfirstreboot -Confirm:$false
Write-EventLog -Message 'Zscaler install task :deleted scheduled task' -LogName System -Source EventLog -EventId 333
if((Get-ScheduledTask -TaskName Install-Zscaleronfirstreboot -ErrorAction SilentlyContinue) -ne $null){
Write-EventLog -Message 'Zscaler Install task : Still exists help me go away'
Unregister-ScheduledTask -TaskName Install-Zscaleronfirstreboot -Confirm:$false
}
}
catch {
Write-Error "Remediation errorred out with $_"
Write-EventLog -Message "Remediation errorred out with $_" -LogName System -Source EventLog -EventId 333
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment