Install/Uninstall Zabbix with Powershell in c:\Program files(x86)\zabbix folder - powershell

in order to distribute Zabbix in our company, I would like to create a function for the Zabbix 5.2 client in my installation script.
This also means that zabbix_agentd.exe is registered as a service with the associated parameters.
I am apparently too stupid to do this with the start-process.
The following line serves as an example .. I've tried a few things but couldn't find a suitable quotation, etc.
start-process -FilePath cmd.exe -ArgumentList "/c c:\program files (x86)\zabbix\zabbix_agend.exe --config C:\Program Files (x86)\Zabbix\zabbix_agentd.win.conf --install"
I also hope that I can transfer the path to zabbix_agentd.exe as a variable
Ih hope someone has a tip.
Thanks in advance

For Windows I use the MSI for installations and check the registry if the correct version is already installed else upgrade.
Replace and for your own.
$zabbixversion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Zabbix SIA\Zabbix Agent (64-bit)").ProductVersion
if ($zabbixversion -eq "5.0.20.2400") {
write-host "Zabbix already installed"
exit
}
else
{
write-host "Uninstall Zabbix Agent"
msiexec /uninstall \\<share>\zabbix_agent-5.0.20-windows-amd64-openssl.msi server=<SERVERIP> sport=10050 lport=10050 SERVERACTIVE=<SERVERIP> rmtcmd=0
write-host "Installing Zabbix Agent"
msiexec /I \\<share>\\zabbix_agent-5.0.20-windows-amd64-openssl.msi server=<SERVERIP> sport=10050 lport=10050 SERVERACTIVE=<SERVERIP> rmtcmd=0
}

You should use the MSI package instead.
You can specify as parameters the host name/ip address of the server, the remote command support, the psk support etc...
You can then launch it with cmd/powershell or even better via GPO
See the documentation page for some of examples

Related

Oracle Clinet silent install failed with exit code -2

I'm trying to install Oracle Clinet 12.2.0 32bit with silent mode. Oracle setup.exe called by my powershell script failed to install with exit code -2. please anyone tell me setup.exe exit code "-2" meaning and how to fix it.
Set-Location C:\Scripts\OracleClient\client32
Write-Host "Starting Oracle Client install"
$process = (Start-Process .\setup.exe -ArgumentList "-silent -force -waitforcompletion -nowait -ignoreSysPrereqs -ignorePrereq -responseFile C:\Scripts\oracleclient.rsp" -PassThru)
$process.WaitForExit()
Write-Host "Oracle Client install Process exit code : " $process.ExitCode
thanks
Seems like -2 stands for that the client is already installed.
It checks it based on the xml files in C:\Program Files (x86)\Oracle\Inventory\ContentsXML
In the Inventory folder there is also a logs folder where you can find more details.
I tested out and found a problem also resulted in -2 when installing version 19c.
Existing environment variable ORACLE_HOME with old path caused the error.
setting it to $null solved my problem.

Installing Windows Updates via PSWindowsUpdate

I am trying to remotely make a domain-computer install its windows updates. This sounds like it should be quite easy, but I've been working on this for over 7 hours now and can't get it to work. I know you can do this via a GPO, but that doesn't give me enough control over the interval. I want our servers to install them and reboot monthly - a GPO can only be used to install and reboot weekly. Since our production works 24/7 I absolutely don't want the servers to reboot outside of the few hours downtime per month I am allowed for maintenance!
I have found several tutorials like this that use the Module PSWindowsUpdate, but these tutorials use an older version of that Module. They use a Function called Invoke-WUInstall which doesn't exist in the newest version. I have tried downgrading the module, but the packagesource doesn't provide versions older than 2.0.0.0
Also the project page doesn't provide a documentation - no examples - neither does it have a discussion or bugtracker. There is a discussion on the page of the original author, but he stopped working on it 2 years ago when it was still the old version.
I tried using Invoke-Command instead of Invoke-WUInstall, but Windows doesn't seem to allow remote update installation like that. PSWindowsUpdate apparently circumvents this problem by running the command as a scheduled task on the target machine, so looking at the output of Get-Command -Module PSWindowsUpdate, I thought I might need to use Invoke-WUJob instead and wrote this code:
Import-Module -Name PSWindowsUpdate
Enable-PSRemoting -Force
ForEach ($hostname in $args) {
Write-Output "Processing $hostname"
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $hostname -Concatenate -Force
# Install PSWindowsUpdate on target machine
Invoke-Command -computername $hostname -ScriptBlock {
PackageManagement\Get-PackageProvider -Name NuGet -Force
inmo PSWindowsUpdate -Force
}
# Install the Updates
Invoke-WUJob -ComputerName $hostname -Script {
ipmo PSWindowsUpdate;
Install-WindowsUpdate -install -AcceptAll -IgnoreReboot
} -Confirm:$false -RunNow
}
I run this as a user who has administrative rights on the target machine and the output looks fine, but it didn't do anything.
Does anyone have experience with that module? how do you do this properly in versions >= 2?
Well, i already did something like this and also faced this same problem.
That was my solution:
Create a powershell file to execute your commands. Place all your commands to install the updates there.
Copy this file to the remote server.
You can do something like this:
copy myfile.ps1 \\myserver\c$\temp\myfile.ps1;
Run a remote script to create a registry inside the RunOnce, and the set value with a command to run your script:
Set-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name '!InstallUpdates' -Value "c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -File c:\temp\myfile.ps1"
Run another command remotelly to restart your server.
The server will reboot and then will execute your script locally.

How to bypass security warning when running EXE from network location?

I am trying to write a complex unattended install script that installs from a network directory. I'm running PS in administrator mode with bypass security.
When I run:
Start-Process "\\192.168.5.7\MSChart.exe" -ArgumentList "/q" -Wait
I get:
How can I bypass this without adding the network location as a trusted server? Ideally simply using PowerShell. I've tried Unblock-File, no luck.
The network share is not trusted by your computer, hence it warns you. You would have to add the share to the trusted zone in the systems internet settings, and allow "launching programs and unsafe files".
You cannot bypass it, but
add the required configuration to the registry
or copy the files locally and run it from there
using PowerShell
You can bypass the warning by adding -NoNewWindow as in Start-Process "\\192.168.5.7\MSChart.exe" -ArgumentList "/q" -Wait -NoNewWindow.
You should however leverage DNS for your path (e.g. \\share.domain.com\file.exe) and ensure the URI (share.domain.com) is in your system 'Trusted Sites' or 'Intranet Sites' list or you may still be blocked. Copying the file to the local system first may also fix the problem.
Reference: https://social.technet.microsoft.com/Forums/en-US/92eab96d-fe1a-4119-a5bc-f171d517466a/getting-open-file-security-warning-using-startprocess?forum=winserverpowershell
Maybe you want to Unblock-File and accept all of the risks that come with that and then try to execute it?
I don't recommend anyone EVER run a script like this:
function Unblock-Dir()
{
gci -Directory | % {
push-location $_ ;
gci | % {
Write-Host "Unblocking $_";
Unblock-File $_
}
Unblock-Dir ;
Pop-Location
}
Unblock-File -path .\*
}
It's just too dangerous.

powershell remote installation of msi fails

I'm trying to install a msi file on a remote server using powershell.
Server 1 is my build server and server 2 is my application server.
When the build server finishes a buil, I want to trigger a powershell script to install the latest version to my application server.
I'm using the following command to create a session and execute the installation:
# Create session to Application Server
$Session = New-PSSession -Name <ApplicationServer> -ComputerName <ApplicationServer> -Auth CredSSP -cred OURDOMAIN\MyUser
# Prepare expression and create script block
$Script = "Invoke-Expression 'msiexec /i <InstallerFile> /qn /L*v C:\Temp\install_fail.log'"
$ScriptBlock = [Scriptblock]::Create($Script)
# Execute in the session
Invoke-Command -ScriptBlock $ScriptBlock -Session $Session
# Clean up the session
Remove-PSSession $Session
The log has the following error (see attachment install_fail.log for full log)
MSI (s) (C4:1C) [17:08:05:333]: Note: 1: 1708
MSI (s) (C4:1C) [17:08:05:333]: Product: WindowsService1 -- Installation failed.
MSI (s) (C4:1C) [17:08:05:335]: Windows Installer installed the product. Product Name: WindowsService1. Product Version: 8.0.0.0. Product Language: 1033. Manufacturer: MyCompany. Installation success or error status: 1603.
When I start a session on the powershell command promt and execute the installation the installation succeeds (see attachment install_success.log for full log):
ENTER-PSSession -ComputerName
Invoke-Expression 'msiexec /i /qn /L*v C:\Temp\install_success.log'
exit
When I print whoami in both cases it returns OURDOMAIN\MyUser.
Microsoft lists the following regarding the 1603: (http://support.microsoft.com/kb/834484)
The folder that you are trying to install the Windows Installer package to is encrypted.
The folder is not encrypted
The drive that contains the folder that you are trying to install the Windows Installer package to is accessed as a substitute drive.
The drive is a partition on the harddisk of the server
The SYSTEM account does not have Full Control permissions on the folder that you are trying to install the Windows Installer package to. You notice the error message because the Windows Installer service uses the SYSTEM account to install software.
The SYSTEM account has Full Control on the drive and all folders.
Please advise...
Have you tried using PSEXEC? or are you using powershell for a reason? I find that easier for remote installs than trying to go through powershell.
Just PSEXEC into the server CMD. Copy the files locally then run MSIExec to install.
I ended up writing a second PowerShell script that runs on the server watching a specific folder for new msi files. The script runs the first script that actually performs the installation tasks.

Execute remote quiet MSI installs from Powershell

I am trying to use the Invoke-Command powershell cmdlet to install a MSI installer. From within powershell on the local machine and from the proper directory, the following works:
./setup /quiet
The following does not seem to work:
$script =
{
param($path)
cd "$path"
& ./setup /quiet
return pwd
}
return Invoke-Command -ComputerName $product.IPs -ScriptBlock $script -Args $sourcePath
For test purposes I am working on the local machine passing in "." for the -ComputerName argument. The paths have been verified correct before passing in to Invoke-Command, and errors generated on different versions of this code indicate the paths are correct. I have also tried with and without the "& " on the remote call to setup. Other Invoke-Command calls are working, so I doubt it is a permissions issue. I have verified that the return from the pwd call is the expected directory.
How do I get the install to work?
What error (if any) are you receiving? Unfortunately, you must run the shell as admin on your local machine to be able to connect to your local machine with invoke-command or any WINRM based command that requires administrative privilege (this is not a requirement when connecting remotely).
When connecting to loopback, I believe it is unable (for some security reason) to enumerate groups and determine if you are in an admin enabled AD or local group, which is how it auto elevates when invoking on a remote machine. The only solution may be to have a conditional which checks for localhost and if so, don't use the -ComputerName parameter.
This GitHub Issue covers it
You might try using Start-Process in your script block:
cd $path
start-process setup.exe -arg "/quiet"
Not sure if you will want or need to wait. Look at help for Start-Process.
I have had weird issues when trying to remotely execute a script on a local machine. In other words, remote powershell to the local machine. It comes back with an error that seems to say that PowerShell remoting is not enabled on the machine, but it was. I can run the script remotely from another machine to the target, but when using remoting to the same box, the issue crops up.
Verify that the WinRM service is running.
Verify powershell remoting has been enabled as in Enable-PSRemoting -force.
Verify your powershell execution policy is loose enough as in Set-ExecutionPolicy Unrestricted, for example. If the policy was set to RemoteSigned, this might be the problem.
You might also want to verify the user you are running the script as (locally, but using remoting) has privileges to "log on as a service" or as a batch job. Just guessing there, if the above list doesn't solve anything.