none
installing MSI with powershell, with parameters in csv file matching the part of computername RRS feed

  • General discussion

  • Is this possible to do something like below. when I run the script on machine named W7DRDS102, it equals the brach in csv file and take the parameters next to it. Is that possible?

    $filePath = "\\server\parameters.csv" $machineParams = Import-CSV $filePath | where {$_.machineCode -eq "$($env:computername.Substring(6))"} | select param1, param2 $machineParams start-process msiexec.exe -Wait -ArgumentList " C:\SMB12\setup.msi" @machineParams

    csv file Branch,DATABASE_ID,ODBC_DATABASE_NAME,ODBC_ENGINE_NAME,ODBC_HOST_NAME 102,1,wwe4564,www002,1.0.0.1


    EDGE

    • Changed type Bill_Stewart Friday, July 27, 2018 7:49 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 7:49 PM Unanswerable drive-by question
    Thursday, May 10, 2018 5:03 PM

All replies

  • It is impossible to understand your question.


    \_(ツ)_/

    Thursday, May 10, 2018 5:11 PM
  • Sorry

    I am trying to install an msi file using powershell script

    we have 300 machine and 50 branches, every branch has different parameters

    So we are creating a csv file for that.

    Now I want to install msi file using the parameters from csv file

    we have computername ending with branch codes

    for example

    W7DGSS102, where 102 is branch code

    $filePath = "\\server\parameters.csv"
     $machineParams = Import-CSV $filePath | where {$_.machineCode -eq "$($env:computername.Substring(6))"} | select param1, param2
     $machineParams
     start-process msiexec.exe -Wait -ArgumentList " C:\SMB12\setup.msi" @machineParams

    And csv file like beow, with the details

    Branch,DATABASE_ID,ODBC_DATABASE_NAME,ODBC_ENGINE_NAME,ODBC_HOST_NAME 102,1,wwe4564,www002,1.0.0.1


    Is that possible?

    Thanks


    EDGE

    Thursday, May 10, 2018 5:25 PM
  • What is your question?  You seem to be asking for someone to design a solution.  We can answer questions.  We cannot design solutions.

    Your CSV is not a CSV.


    \_(ツ)_/

    Thursday, May 10, 2018 5:28 PM
  • Thanks

    Its just a question

    I coped the header and line from csv.

    what changes do i have to make to my script above, to make that work work with csv


    EDGE

    Thursday, May 10, 2018 5:32 PM
  • You have to loop through the CSV and select the fields you want to apply to the command.


    \_(ツ)_/

    Thursday, May 10, 2018 5:34 PM
  • Thanks

    $filePath = "parameters.csv" 
    
    $machineParams = Import-CSV $filePath | where {$_.machineCode -eq "$($env:computername.Substring(7))"} | select DATABASE_ID,ODBC_DATABASE_NAME
    $machineParams # this is just so it shows info on the host
    
    start-process msiexec.exe  -Wait -ArgumentList   "setup.msi" @machineParams

    when I run this

    I get error

    "Start-Process : A positional parameter cannot be found that accepts argument '$null'."

    Also which command I can use to loop into csv?

    regards

    Aj


    EDGE

    Thursday, May 10, 2018 5:38 PM
  • ArgumentList requires an array and not a set of strings and objects.


    \_(ツ)_/

    Thursday, May 10, 2018 5:41 PM
  • $filePath = "parameters.csv" 
    
    $machineParams = Import-CSV $filePath | where {$_.machineCode -eq "$($env:computername.Substring(7))"} | select DATABASE_ID,ODBC_DATABASE_NAME
    $machineParams # this is just so it shows info on the host
    
    start-process msiexec.exe  -Wait -ArgumentList  /qn /i  "setup.msi" @machineParams
    i changed it now i am getting erreor "Start-Process : A positional parameter cannot be found that accepts argument '/i'"

    EDGE

    Thursday, May 10, 2018 5:48 PM
  • You need


    -ArgumentList "/qn","/i"


    -- Bill Stewart [Bill_Stewart]

    Thursday, May 10, 2018 5:51 PM
  • Sorry for that,

    I made

    $filePath = "parameters.csv" 
    
    $machineParams = Import-CSV $filePath | where {$_.machineCode -eq "$($env:computername.Substring(7))"} | select DATABASE_ID,ODBC_DATABASE_NAME
    $machineParams # this is just so it shows info on the host
    
    start-process msiexec.exe  -Wait -ArgumentList  "/qn", "/i"  "setup.msi" @machineParams

    changes

    its throwing  "

    Start-Process : A positional parameter cannot be found that accepts argument 'C:\Users\ARAVIND ANCHE\Desktop\TI18 setup\tellerinsight.msi'.
    At C:\Users\ARAVIND ANCHE\Desktop\test.ps1:8 char:14
    + start-process <<<<  msiexec.exe  -Wait -ArgumentList  "/qn", "/i" "setup.msi" @machineParams
        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
     Start-Process : A positional parameter cannot be found that accepts argument 'setup.msi'.
    At Desktop\test.ps1:8 char:14
    + start-process <<<<  msiexec.exe  -Wait -ArgumentList  "/qn", "/i" "setup.msi" @machineParams
        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
     

    EDGE

    Thursday, May 10, 2018 5:56 PM
  • So "setup.msi" is also part of the arguments, so you need to include it in the list.

    I think you would be helped by reading the documentation.


    PS C:\> Help Start-Process -Full


    -- Bill Stewart [Bill_Stewart]

    Thursday, May 10, 2018 5:57 PM
  • start-process msiexec.exe  -Wait -ArgumentList  'setup.msi /qn /I'

    \_(ツ)_/


    • Edited by jrv Thursday, May 10, 2018 5:58 PM
    Thursday, May 10, 2018 5:58 PM
  • @jrv

    Thanks

    I changed that to 

    "start-process msiexec.exe  -Wait -ArgumentList  'setup.msi /qn /I'"

    its throwing "Start-Process : A positional parameter cannot be found that accepts argument '$null'."


    EDGE

    Thursday, May 10, 2018 6:02 PM
  • Thanks Bill,

    I will take a look


    EDGE

    Thursday, May 10, 2018 6:02 PM
  • Also - there's no machineCode column in your CSV file.

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 10, 2018 6:37 PM
  • Thanks Bill

    Branch is machine code, machine name is W7Dysr101 where 101 is brach code


    EDGE


    • Edited by DJ3094 Thursday, May 10, 2018 6:39 PM
    Thursday, May 10, 2018 6:38 PM
  • The column name in the CSV file has to match what you put in your code. (It does not, currently.)

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 10, 2018 7:25 PM
  • $filePath = "parameters.csv" 
    
    $machineParams = Import-CSV $filePath | where {$_.Branch -eq "$($env:computername.Substring(7))"} | select DATABASE_ID,ODBC_DATABASE_NAME
    $machineParams # this is just so it shows info on the host
    
    start-process msiexec.exe  -Wait -ArgumentList  "/qn", "/i"  "setup.msi" @machineParams
    I changed that Bill

    EDGE

    Thursday, May 10, 2018 7:35 PM
  • I will say this yet again.  You cannot pass a CSV as an argument or as a splat.


    \_(ツ)_/

    Thursday, May 10, 2018 7:41 PM
  • thanks Jrv

    What will be ideal path in my case

    as we have 500 branches

    please point me to right direction.

    Thanks


    EDGE

    Thursday, May 10, 2018 7:46 PM
  • What are you trying to do?  The information provided is to vague.

    As I noted at the beginning of this thread, you need to process the CSV in a loop and apply each required field where needed.

    Import-Csv <file> |
         ForEach-Object{
               # code
         }


    \_(ツ)_/

    Thursday, May 10, 2018 7:50 PM
  • Thanks Jvr

    I will be using script on 1500 PC, across 500 branches.

    All the data is in csv

    I have to install the msi with the parameters from CSV

    Import-Csv "parameters.csv"

    ForEach-Object

    {

    $filePath = "parameters.csv" $machineParams = Import-CSV $filePath | where {$_.Branch -eq "$($env:computername.Substring(7))"} | select DATABASE_ID,ODBC_DATABASE_NAME $machineParams # this is just so it shows info on the host start-process msiexec.exe -Wait -ArgumentList "/qn", "/i" "setup.msi" @machineParams

    }



    EDGE

    Thursday, May 10, 2018 8:01 PM
  • Until you learn PowerShell there is no way we can help you since you don't seem to understand even the most basic instructions.

    We will not try to guess at how to write your script.  With the information you have provided there is no way to even guess at the first step.

    Start here:

    Learn PowerShell  
    PowerShell Documentation 
    PowerShell Style Guidelines


    \_(ツ)_/

    Thursday, May 10, 2018 8:15 PM
  • I think I see what you are trying to do.  You are running the script locally  on a given PC.  You are attempting to match the last three characters of the computer name from the environment with the Branch field in the CSV.  If you find a match you want to use the info in that record as parameters for the Setup.msi started with msiexec.exe.

    You have two problems to overcome.  First is selecting the correct record from the CSV.  Is it displaying the correct branch info since you made the change to use $_.Branch as Bill suggested?  If not you need to work on that until it does.

    Once you have the correct record you will need to format the command line to match the needs of your installer.  I seriously doubt that you can just plop the variable on the line and it will work.  Find the correct layout that you need and work on formatting the to match that layout.

    Thursday, May 10, 2018 9:15 PM