Silent install of Office using a variable

Krzysztof Kołodziejczyk 20 Reputation points
2023-02-03T13:50:57.6933333+00:00

Hello I`ve wrote a script for installing programs directly from USB drive in powershell, but as before i used the just the paths so

start-process "D:\programs\program.exe" for ex.

everything was fine but then it stroke me that some computers might assign my USB Drive a different letter, therefore I`ve put up a variable "$P = volume | ? drivetype -eq removable | % driveletter" that gets the letter of currently plugged in USB (obviously working only when only one is in) but as all below command works

start-process "${P}:\programs\program.exe"

the issue I have is silent office install as with path projected it works
D:\office\setup.exe /configure D:\office\configuration.xml
with variable
${P}:\office\setup.exe /configure ${P}:\office\Configuration.xml

It doesn`t put the variable as the assigned letter and when i try to put the whole path into a variable it so for ex.
$D ="${P}:\office\setup.exe"
it says /configure is wrong
cannot user start-process cause /configure is also not working there, can someone please tell me what can i fix it?

Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,359 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,161 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 32,246 Reputation points
    2023-02-03T14:57:36.91+00:00

    Try this.

    $cmd = "$($P):\office\setup.exe /configure $($P):\office\Configuration.xml"
    $cmd
    Invoke-Expression $cmd 
    
    

    If you need the script to continue executing while setup.exe is also running, then try this.

    Start-Process "$($P):\office\setup.exe" -ArgumentList  "/configure $($P):\office\Configuration.xml"
    

1 additional answer

Sort by: Most helpful
  1. Krzysztof Kołodziejczyk 20 Reputation points
    2023-02-03T15:23:20.6666667+00:00

    Found a solution simply before the silent install I`ve put

    $P = volume | ? drivetype -eq removable | % driveletter

    cd ${P}:\

    \office\setup.exe /configure \office\configuration.xml

    And now it works

    0 comments No comments