You must provide a value expression on the right side of the '/' operator

It works

Dependencies\iis7psprov_x86.msi /qn /l* $SnapinInstallLog 

But it is not

 $SnapinInstaller = "Dependencies\iis7psprov_x86.msi" $SnapinInstaller /qn /l* $SnapinInstallLog 

I get the following error: You must specify a value expression on the right side of the '/' operator. + $ SnapinInstaller / q <<<n / l * $ SnapinInstallLog

How to get snap-ins for installation using the $ SnapinInstaller variable?

+4
source share
2 answers

PowerShell recognizes $SnapinInstaller as a variable and evaluates it for the string. If you want PowerShell to β€œinvoke” a command called a variable, you use the & call operator as follows:

 & $SnapinInstaller /qn /l* $SnapinInstallLog 

While you can use Invoke-Expression , this is usually avoided, especially with user-provided data, due to the possibility of a script attack, for example:

 PS> $SnapinInstallLog = Read-Host "Enter log file name" Enter log file name: c:\temp\snapin.log; remove-item C:\xyzzy -r -force -whatif PS> Invoke-Expression "$SnapinInstaller /qn /l* $SnapinInstallLog" 

The problem occurs here because the user was able to enter an arbitrary script.

OTOH, if you have bunch arguments presented on the same line (and without user input), Invoke-Expression can come in handy in this scenario, for example:

 $psargs = "\\$computer -d -i 0 notepad.exe" Invoke-Expression "psexec.exe $psargs" 
+9
source

This is because powershell treats $ SnapinInstaller as a string, not a command.

The first way to do what you want, I can remember is to write

Invoke-Expression -Command ($ SnapinInstaller + "/ qn / l *" + $ SnapinInstallLog)

This works with * .exe, I have not tried it with * .msi.

0
source

Source: https://habr.com/ru/post/1336329/


All Articles