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.
Related
I have several, systems (MS OS) that have the Tenable Nessus agent installed in my environment. I am attempting to re-link the agent to the management portal via PowerShell. I will be using SCCM to execute, the script so I created a simple PS script with one line of code that will execute the script remotely on the workstation. I can execute the script locally using powershell no problem, on errors, and the Nessus agent re-links.
I am sure, I am overlooking something. Here is my script
Invoke-Command -ScriptBlock { Start-Process 'C:\Program Files\Tenable\Nessus
Agent\nessuscli.exe' -ArgumentList 'agent link --
key=<License Key> --
host=<hosted portal here> --port=<port>' -Passthru -NoNewWindow
Thank you for your time
I try the "run powershell on remote machines" task to restart my Tomcat (java) service on the Windows server.
It just keep printing useless info in the console (target machine name)
Here is the detail about the powershell script:
stop Tomcat service (call a .bat file)
move .jar files to right location & replace old files
start Tomcat service (call a .bat file)
& D:\MY\PATH\stop.bat;
......
Copy-Item -Path "D:/s-1.0.jar" -Destination $sqs_path -Force;
......
& D:\MY\PATH\start.bat;
When I run the same command directly in target windows server, the "powershell part" trigger .bat script job, then get back to powershell console successfully .
Later, a new window pops out. The new window is Tomcat server that shows logs of my service.
However, when I do the same job with Azure release pipeline, the Tomcat window did not show up in target machine.
And release job console keep hanging (just print the name of targer machine).
I guess somewhat the output of popout window has be redirected to the console in release pipeline.
In addition, if I cancel the release job. my Tomcat service still working. (just without console to debug)
Or, another thought, can I achieve my goal with other 'task' in release pipeline? (powershell is not a "must")
Any suggestion would be appreciated.
[Update1]
I change the service start commamd to run the .bat in another window.
& D:\MY\PATH\stop.bat;
......
Copy-Item -Path "D:/s-1.0.jar" -Destination $sqs_path -Force;
......
Start-Process cmd.exe -ArgumentList "/C D:\sources\SQS.Dev\start.bat;"
And it turns out "nothing happens" ...
The remote powershell task finish immediately.
The PowerShell on Target Machines task uses WinRM to connect and access the remote target machine.
Normally, WinRM requires the agent machine and the remote target machine have been joined into the same domain or workgroup.
Please check with the following things:
Ensure the agent machine and the remote target machine have been joined into the same domain or workgroup.
Ensure you have followed the steps here to configure the WinRM.
If you have configured the WinRM. Login to the agent machine, ensure you can connect and access the remote target machine when you manually try to call the remote PowerShell. You can try with the following script on the agent machine to test if the WinRM can work well to connect and access the remote target machine.
Param(
# The IP address or FQDN of the remote machine
[string]$computerIp = "{computerIp}"
)
# Username and Password of the admin account on the remote machine
$Username = "{Username}"
$Password = ConvertTo-SecureString "{Password}" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($Username,$password)
# Call the remote PowerShell script
Invoke-Command -ComputerName $computerIp -Credential $cred -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"powershell.exe /c '{absolute path of the remote PowerShell script}'"}
If it does not work when you try manually calling the remote PowerShell script on the agent machine, the task in the pipeline of course is not able to work. The issue should be on the WinRM, maybe, the WinRM is not configured well.
If it work well when you manually try on the the agent machine, the issue should be on the self-hosted agent. Try to set up a new self-hosted agent with the admin account to see if it can work.
[UPDATE]
As I mentioned above, please try manually calling the remote PowerShell script on the agent machine to see if the commands for 'start Tomcat service' can work.
The PowerShell on Target Machines task is running on the agent machine. If the remote PowerShell script cannot work as expected when you manually try it on the agent machine, it is of course not able to work on the task in pipeline.
At this time, the possible reason of the issue could be the following:
The connection between the machines has some problems.
The PowerShell script has some issues. Maybe you missed some settings for remoting call the script.
I'm trying to automate the upgrading of Spotfire BI system on our Windows servers.
The instructions show a command that can be used to silently install which states the location of the executable file followed by all the required options/parameters as shown with this example:
install.exe INSTALLDIR="<node manager installation dir>" NODEMANAGER_REGISTRATION_PORT=9080 NODEMANAGER_COMMUNICATION_PORT=9443 SERVER_NAME=SpotfireServerName SERVER_BACKEND_REGISTRATION_PORT=9080 SERVER_BACKEND_COMMUNICATION_PORT=9443 NODEMANAGER_HOST_NAMES=NodeManagerHostNames NODEMANAGER_HOST=NodeManagerHost -silent -log "C:\Users\user\Log file.log"
This does work, and as long as it preceded by the call operator (&), it runs well in PowerShell. However, I can't get it to work when running this on a remote server:
function nodeManagerUpgrade {
Param([String]$ServiceName1,
[String]$InstallDirectory,
[String]$HostNames1
)
Stop-Service $ServiceName1
# this is the line that fails
& "X:/downloads/spotfire/install.exe" INSTALLDIR="$InstallDirectory" NODEMANAGER_REGISTRATION_PORT=17080 NODEMANAGER_COMMUNICATION_PORT=17443 SERVER_NAME=localhost SERVER_BACKEND_REGISTRATION_PORT=19080 SERVER_BACKEND_COMMUNICATION_PORT1=9443 NODEMANAGER_HOST_NAMES=$HostNames1 -silent -log "install.log"
}
Invoke-Command -ComputerName $NodeIP -ScriptBlock ${function:nodeManagerUpgrade} -argumentlist ($ServiceName,$InstallDirectory,$HostNames) -credential $credentials
I can run the code contained in the function directly on the remote server and it works correctly. However, when I try and run it from the central server through WinRM/Invoke-Command within a function, it fails giving me this error:
The term 'X:/downloads/spotfire/install.exe' is not recognized as the name of a cmdlet
Is it possible to run an executable using PowerShell on a remote server?
Your executable path is based on a drive letter, X:.
However, in remote sessions mapped drives (drives connected to network shares) aren't available by default, so you have two options:
Establish a (temporary) drive mapping with New-PSDrive before calling the executable (e.g., $null = New-PSDrive X FileSystem \\foo\bar)
More simply, use the full UNC path of the target executable (e.g. & \\foo\bar\downloads\spotfire\install.exe ...)
If the target executable isn't actually accessible from the remote session, you'd have to copy it there first, which requires establishing a remote session explicitly and using Copy-Item -ToSession - see the docs for an example.
I have a code deploy project with an app spec.yml file. It has a list of hooks that call powershell scripts.
The code deploy has scripts within that is moved onto the ec2 machine. I’m then trying to use scripts within my app spec to call the scripts copied to the deploy folder
version: 0.0
os: windows
files:
- source: /deploy
destination: /things
hooks:
AfterInstall:
- location: ./install.ps1
timeout: 300
These powershell scripts call other batch files to setup services
# Fail on all errors
$ErrorActionPreference = 'Stop'
# Are you running in 32-bit mode?
# (\SysWOW64\ = 32-bit mode)
if ($PSHOME -like "*SysWOW64*")
{
Write-Warning "Restarting this script under 64-bit Windows PowerShell."
# Restart this script under 64-bit Windows PowerShell.
# (\SysNative\ redirects to \System32\ for 64-bit mode)
& (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File `
(Join-Path $PSScriptRoot $MyInvocation.MyCommand) #args
# Exit 32-bit script.
Exit $LastExitCode
}
D:
cd d:/install/scripts
Call installservices.bat
And then the batch script looks like this..which installs a windows service
App.exe /install
App2.exe/install
The issue I am running into is when the code deploy executes these powershell scripts it’s from a specific “environment” for code deploy but not as a user on windows.
It executes under this directory C:\Windows\system32
So the installer that is called automatically is not able to find a user data folder on the current executing user to drop config files to complete the install.
If I manually run the powershell script from the directory it works fine as I’m logged in as user, its in the context of code deploy executing the script that it no longer works
Is there a way to execute power shell scripts outside of how code deploy executes it, or execute as a specific user on windows?
I see Linux has a run as option for their app spec, but that option is not for windows.
This is on a windows Ec2 machine
whenever an .exe file is executed on remote machine with help of pssession and invoke-command with start-process..
it the execuable runs in background , i am able to see the process in task manager but cpu alloted to that process is 0% and also it keeps running.
i want to pop up GUI of executable file on remote machine whenever i run script.
i tried..
1)
Invoke-Command -ScriptBlock {Start-Process -Wait -FilePath 'C:\Documents and Settings\user\Desktop\scripts\dbsetup_trial.exe' -ArgumentList '/S' -PassThru -Verb runas}
2) by enetring in PSsession, i tried executing exe, bt result was same.
please help me out.
i need to install file , if silent installation is option it should install file silently or just pop the window of executable and return back.
You cannot invoke a GUI on a remote system's interactive session via PowerShell. PowerShell remote sessions are unable to interact with other sessions, especially the logged-on user session(s).
psexec can do this, but the better way to do this is to run a silent/unattended install if it's an option with that application installer. We can't answer that because we don't know what that installer is or how it's made.