So I have been looking for a day or so now on a way to get microsoft teams installed on workstations. This is my code that I have used to write scripts for many other MSI's and Exe's. I got this file from microsofts documentation for installing teams
$file = C:\Teams_windows_x64.msi
$Arguments = #(
"/i"
(' "{0}" ' -f $file.fullname)
"/quiet"
"/norestart"
'OPTIONS="noAutoStart=true" '
"ALLUSERS=1"
)
Start-Process "msiexec.exe" -ArgumentList $Arguments -Wait -NoNewWindow
when i do this for just about any other MSI or EXE ill get it to work. However, I have not been able to get this to work at all. All it does is await more input after I press enter. I do know that there is a microsoft teams module but id prefer not to use that. I know that this may be a weird way of having a collection of arguments but this is how ive always done it. Thank you
Edit: thought I should mention that the reason why im trying to install it with a file already on the computer is because i use DattoRMM and they have a way for you to upload the file you wanna use and then reference it in the script. but im trying to get it to work on my local computer first.
Posting the Answer for better knowledge
Copying from #MrClayGiovanni comments
For this particular software we couldn’t install it this way
I am creating a script that will check if a file is in the downloads folder, silently install if found or silently download if not found.
Steps:
Look in the downloads folder for the .exe file
Silently install the .exe file if found
Silently download the .exe file from a URL if not found, then silently install
I am not sure how to silently perform the above, I keep getting a window that pops up showing the download. Here is my script, I am a beginner with PS so go easy on me
if ( Get-ChildItem -Path C:\Users\*\Downloads\7z1900.exe )
{
7z1900.exe /install /norestart /quiet
}
else {
start /quiet "https://www.7-zip.org/a/7z1900.exe"
}
How about using curl cmdlet?
curl http://some.url --output some.file
Or in your case
curl https://7-zip.org/a/7z1900-x64.msi --output 7z1900-x64.msi
Followed by
7z1900-x64.msi /quiet
(I have used the *.msi file, since the exe does not seem to support a silent installation)
I've built a few FFmpeg powershell scripts for me and a few others to use and I'm attempting to make the setup and update process as easy as possible. The end goal is to be able to run 1 batch file that installs Chocolatey, FFmpeg, git, clones the github repo (for updates), and edits the Windows registry to add the actual FFmpeg powershell scripts / console programs to the Windows Explorer contextual menu. This way I just pass them the folder containing everything once and any time I change or add something to the project I can just tell them to run the batch file again, and presto everything is up to date.
However I'm struggling to find a way to install Chocolatey, then git with Chocolatey, and then run a git command with the execution of a single .bat file. From what I can tell after installing Chocolatey I need to restart the shell entirely before I can install git, and then I have to restart the shell again before I can use a git command. As of right now most of the actual processing is happening via Powershell scripts that are launched from the .bat file, and as each step is taken I update a txt file, attempt to restart the batch script, and read the txt file to pick up where I left off:
#echo off
echo Administrative permissions required. Detecting permissions...
echo.
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
echo.
) else (
echo Failure: Current permissions inadequate.
PAUSE
exit
)
set relativePath=%~dp0
set relativePath=%relativePath:~0,-1%
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%relativePath%\Setup\CheckRequiredPackages.ps1" -relativePath "%relativePath%"
set /p step=<"%relativePath%\Setup\Step.txt"
if %step% == 1 (
(echo 2) > "%relativePath%\Setup\Step.txt"
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%relativePath%\Setup\GetChocolatey.ps1"
start "" "%relativePath%\RunMe.bat"
exit
)
if %step% == 2 (
(echo 3) > "%relativePath%\Setup\Step.txt"
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%relativePath%\Setup\GetRequiredPackages.ps1"
start "" "%relativePath%\RunMe.bat"
exit
)
if %step% == 3 (
(echo 0) > "%relativePath%\Setup\Step.txt"
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%relativePath%\Setup\Update.ps1" -relativePath "%relativePath%"
)
PAUSE
Exit
The problem is using the start command in the batch script doesn't seem to work, I'm guessing since that new process is spawned from the same process that handles the Chocolatey install it doesn't count as actually restarting the shell. Is there any way to actually restart the shell and somehow have the batch file start back up without user intervention?
I'm not sure why I didn't initially think of reloading the path environment variable but that's a whole lot more reasonable than restarting the script 4 times with an intermediary file.
Firstly I moved 99% of the heavy lifting from the .bat file to a Powershell script, as the only reason I'm using Batch is so the user can easily run the file by clicking it in Explorer. I couldn't get RefreshEnv to work, which is a feature of Chocolatey, but running this between each new package worked great:
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
So I have something like this now, and the Batch scrip just launches this Powershell Script:
Write-Host "Installing / updating required packages..."
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
choco install ffmpeg -y
choco install git -y
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "Deleting old files..."
Remove-Item -LiteralPath $relativePath -Force -Recurse
Start-Sleep 2
Write-Host "`nUpdating Files..."
git clone https://github.com/TheNimble1/FFmpegContextCommands.git $relativePath
Which installs Chocolatey, refreshes the path, installs FFmpeg & Git, refreshes the path, deletes the old files, and then clones the git to replace with new files.
Indeed, a start-launched process inherits the calling process' environment rather than reading possibly updated environment-variable definitions from the registry.
Chocolatey comes with batch file RefreshEnv.cmd (C:\ProgramData\chocolatey\bin\RefreshEnv.cmd, but C:\ProgramData\chocolatey\bin should be in the %PATH%) specifically to avoid having to start a new, independent session for environment updates to take effect.
Therefore, something like the following may work:
:: Assumes that Chocolatey was just installed to the default location.
call "%ProgramData%\chocolatey\bin\RefreshEnv.cmd"
:: If Chocolatey was *previously* installed and its installation directory
:: has already been added to %Path%, the following will do:
:: call RefreshEnv.cmd
call "%relativePath%\RunMe.bat"
Since Chocolatey is only being installed during your script's execution and its binaries folder is therefore not yet in %Path%, you'll have to call RefreshEnv.cmd by its full path, as shown above - which assumes the default install directory.
Your own answer now shows how to refresh the $env:Path (%Path%) environment variable using .NET methods directly _from PowerShell, which is a pragmatic solution.
Note, however, that RefreshEnv.cmd is more comprehensive in that it reloads all environment-variable definitions and therefore potentially newly added and modified ones.
Note that calling RefreshEnv.cmd from PowerShell does not work, because it then runs out of process (which means that it cannot update the calling process' environment).
However, Chocolatey offers an Update-SessionEnvironment PowerShell command (aliased to refreshenv), which you can make available immediately after a Chocolatey install as follows:
# Import the module that defines Update-SessionEnvironment aka refreshenv
Import-Module "$env:ProgramData\Chocolatey\helpers\chocolateyProfile.psm1"
# Refresh all environment variables.
Update-SessionEnvironment # or: refreshenv
See this answer for a more robust approach that doesn't rely on assuming that the default location was installed to.
Using the powershell app deployment toolkit I am trying to write a script to push a Windows update (MSU).
This is what I have, but it does not seem to work?
Execute-Process -Path 'Windows6.1-KB3033929-x64.msu' -Parameters "/quiet"
Msu-files are installed using wusa.exe. Try:
$PathToMsu="$PSScriprRoot\somefile.msu" Execute-Process -Path 'wusa.exe' -Parameters "`"$PathToMsu`" /quiet /norestart"
You might also consider using Install-MSUpdates from the toolkit which does this for you for every file in a directory.
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.