Error Creating Logfile During Silent Installation - powershell

I'm experiencing an error creating a logfile during an application installation script. This is the first time I've used PowerShell for this purpose. The reason for using it is that I need to dynamically build the option string during the installation, based on other software installed on the server.
The MCVE to generate the error is as follows:
$cmd = '"Installer.exe" /s /v"INSTALLDIR=D:\ OPTION_1=VALUE_1 OPTION_2=VALUE_2 OPTION_3=VALUE_3 REBOOT=ReallySuppress /L*v \"C:\Temp\Install_Log.log\" /qb"'
Invoke-Expression "cmd /c ${cmd}"
The error I receive is:
Error opening installation log file. Verify that the specified log
file location exists and is writable.
Note that /qb is being used for debugging purposes only. It will be changed to /qn prior to deployment; the script also fails when /qn is used.
However, when I open a Command Prompt in the correct folder and paste the contents of $cmd into it, the application installs as expected. It also works as expected if I remove /L*v \"C:\Temp\Install_Log.log\" from $cmd. The log path does exist. I have also attempted to create the log file prior to executing the installer, but this also failed.
I'm developing and testing this in PowerShell v2.0, if that matters, since some of the servers this will be deployed to have 2.0 installed.

Related

Powershell script failing from teamcity, running fine upon manual run

I have a powershell script which creates a new login in a database.
The script runs fine when I run from powershell ISE or console but it fails when I run it from Teamcity or use teamcity command manually.
C:\windows\sysnative\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File C:\DB_Deploy\DB_Deploy.ps1 && exit /b %ERRORLEVEL%
The error I get is
Validation Error: Error while checking backup file
The .bak backup file is at a shared remote location.
I suppose the problem, while running from teamcity, is in opening the backup file.
The same runner config works for other powershell scripts, the ones not involving opening of any file on remote location.

Error trying to pass in variables when calling MSI file

I am very new to using Powershell but keen to learn.
I am attempting to install a MSI package, using PowerShell and passing in some variables. The end result is for this to be an unattended installation deployed via Jenkins using PowerShell. Please keep in mind I have changed the port numbers for this example:
msiexec /i /quiet $SYSTEMID ="PC01" $PORT1 =0000 $PORT2 =0001 $TARGETDIR ="C:\Application\" "C:\MSIPackage64bit.msi"
When trying to run the above I get presented with a Windows ® Installer. pop up which lists a load of MSIExec variable options.
I have been looking on the web for quite some time and now believe I'm having issues due to my lack of understanding when it comes to PowerShell.
/I needs to be followed by the path to the MSI to be installed. Also get rid of the $ in front of the property names. Finally TARGETDIR isn't always TARGETDIR. Some MSIs are authored as INSTALLDIR, INSTALLLOCATION and other possible directory table entry names. Adding logging ( /l*v path_to_log ) is usually a good choice also.
PS- Please note that since you are doing a silent installation you need to either be installer per-user without need for elevation or you need to already be elevated.

Powershell does not create a folder when I run a script. What's wrong?

I'm trying to have powershell create a folder for me and it works fine when I type it into the console. However, when I run the same command as a script, no folder is created and no error messages are supplied.
This is the line of code I am using.
new-item - path c:\test\ -name testfolder -itemtype directory
edit: I am on Windows 7
This should be a comment, but I cannot comment. There is definitely nothing wrong with that line of code. It runs on my machine, either from the terminal window or as a script. Because the code works for you at the terminal window but not when executing as a script my first guess is that your system may be configured to disallow powershell scripts. This is the default setting, and it will prevent a script file from executing but will not prevent commands typed at the prompt from working. Open a powershell session and type get-executionpolicy. If it returns "restricted" then you have found the culprit. This setting can be changed by opening an elevated powershell session (run as admin) and typing set-executionpolicy -executionpolicy RemoteSigned. Of course you should read about what those settings mean before changing them to determine what is best for your situation. For example the remotesigned option means that scripts originating from your machine will execute without a trusted signature, but external scripts will require a signature.

Getting error while installing "azure-powershell.0.8.7.msi" through .cmd file

I am trying to install “azure-powershell.0.8.7.msi” through a .cmd file using command
msiexec.exe /i ".\azure-powershell.0.8.7.MSI" /passive
This msi file is part of solution explorer(part of project, I have to do it in this way only).
Although I am able to install/uninstall when this msi file when it’s on local disk ( i.e. on some drive)
I tried to log the error it is:
“This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.”
It is a known error of Microsoft. I tried each and every proposed solution on internet but it doesn’t work.
Note: The current user/admin of the system have all the access(read,write,modify).
if your MSI-file is in the same directory like the cmd-file you have to us the following command
msiexec /i "%~dp0azure-powershell.0.8.7.MSI" /qb
%~dp0 is refering to cmd-file directory and in this case to the MSI-file.
If you want to create a log-file use the /l and the logfilepath plus name after /qb.
For example:
msiexec /i "%~dp0azure-powershell.0.8.7.MSI" /qb /l*v %temp%\azure-powershell.log

Powershell script works when remoted in, but not as Azure startup task

I have an powershell script saved in a .cmd file that downloads a file from the web and then unzips it. My azure web role executes it upon startup. This is the script:
powershell -ExecutionPolicy Bypass -c $(New-Object Net.WebClient).DownloadFile('URL.zip', 'FILE.zip') ;
(New-Object -com shell.application).namespace('c:\FOLDER').Copyhere((New-Object -com shell.application).namespace('FILE.zip').items())
When I run the script via Azure startup tasks:
The first part of the script works. The file is downloaded. The second part of the script which unzips does not run.
When I run the script via the command line when remoted into the VM:
The entire script runs.
I therefore know this is not a syntax error. The only difference I can think of between the two cases above is a permissions issue. But, I am running powershell with -ExecutionPolicy set to Bypass, which is the highest permission level. Anybody have any ideas? Thanks!
Change the command so that the output of the command is dumped into a file. Something like this should work
<YOUR_COMMAND> > out.log 2> err.log
Run the task again and checkout the output in the logs.
Also, you are using relative paths rather than absolute ones. The scheduled task probably run with the windows system folder as its working directory, so you may be getting a permissions error from that. Try using an absolute path to a directory you created.