How install Cognos Contributor client with a Powershell script

Product:

Cognos Planning 10.1.1

Cognos Insight

Windows 2008 R2 server

Windows 7 client

 

Problem:

How install Cognos Contributor client or Cognos Insight with a Powershell script ?

 

Script to save in notepad as a file named installrcp.ps1:

#MSI Configuration

#Variables

$computername = Get-Content ‘\\servername.domain.com\cognos102\response\plan\plan_contributor_client\computerTest.txt’

$sourcefile = “\\servername.domain.com\cognos102\response\plan\plan_contributor_client\*”

$para0= ” /i”

$para1= ” ALLUSER=1″

$para2= ‘ TARGETDIR=”c:\program files (x86)\ibm” ‘

$para3= ” NOUPDATE=Yes”

$para4= ” /qn /passive”

#

#This section will copy the software to computer in list

#

foreach ($computer in $computername)

{

$destinationFolder = “\\$computer\C$\download\cognos”

#This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.

if (!(Test-Path -path $destinationFolder))

{

New-Item $destinationFolder -Type Directory

}

Copy-Item -Path $sourcefile -Destination $destinationFolder

}

#

#This section will install the software

#

$currentLocation = “c:\download\cognos\”

$msi = @(‘contributor.msi’, ‘cognosrcp.msi’)

foreach ($msifile in $msi)

{

##

## write-host is for debug to show result of variabled in powershell-ise

## write-host “$env:systemroot\system32\msiexec.exe” -ArgumentList $para0, $msifile , $para1, $para2, $para3 , $para4 -Wait -WorkingDirectory $CurrentLocation

 

## call the msiexec.exe with paratmeters and starts

##

Start-Process -FilePath “$env:systemroot\system32\msiexec.exe” -ArgumentList $para0, $msifile , $para1, $para2, $para3 , $para4 -Wait -WorkingDirectory $CurrentLocation

}

 

 

Solution:

Text files save as PS1 will be run and executed by the Power Shell engine in Windows OS.

 

To prepare above, you need to create a file share, \\servername.domain.com\cognos102\response\plan\plan_contributor_client

where you place the msi files to install and a text file;

contributor.msi

cognosrcp.msi

computertest.txt

 

The text file computertest.txt should contain the names of the workstations where you want to install the software.

 

The PS1 file should be on the share, and started from the client computer where you want to install.

 

In the script the variables are set in the beginning:

$computername = Get-Content ‘\\servername.domain.com\cognos102\response\plan\plan_contributor_client\computerTest.txt’

$sourcefile = “\\servername.domain.com\cognos102\response\plan\plan_contributor_client\*”

You need to change servername.domain to the path to your file share for this installation.

 

 

“\\servername.domain.com\cognos102\response\plan\plan_contributor_client\*”

The * at the end of the source file path means it will copy all files in this folder locally.

 

$para0= ” /i”

$para1= ” ALLUSER=1″

$para2= ‘ TARGETDIR=”c:\program files (x86)\ibm” ‘

$para3= ” NOUPDATE=Yes”

$para4= ” /qn /passive”

The parameters are for the installation of the MSI;

/i is to tell it to install

ALLUSER=1 is to make the program available to all users on the PC not only the one installing it. This mean it will write values to other paths in registry can CURRENT_USER.

TARGETDIR= is the path to where the software will be install, program files is better than in the windows user profile folder ( c:\user\%username%\AppData\Roaming\IBM\Cognos Insight)

NOUPDATE=Yes will prevent the client software from downloading and update itself when there is a new version of the client on the Cognos Server.

$para4= ” /qn /passive”

Will not show any prompts or error dialogs during the installation, only a progress bar.

 

foreach ($computer in $computername)

This is a loop function – for each item in the variable list, the steps in the parentheses below are done. Foreach take all items in the list, it does not do any conditional testing.

 

$destinationFolder = “\\$computer\C$\download\cognos”

This give the variable $destinationFolder the value in ” ” – in this case the contain of variable $computer and the path.

if (!(Test-Path -path $destinationFolder))

{

New-Item $destinationFolder -Type Directory

Above will check if path exist, if not it will create the folders.

 

Copy-Item -Path $sourcefile -Destination $destinationFolder

This will copy all files from $sourcefile folder to the $destinationfolder catalog.

 

$currentLocation = “c:\download\cognos\”

This will set variable where the MSI files to install are.

 

$msi = @(‘contributor.msi’, ‘cognosrcp.msi’)

Here you list the msi files to install, you can add more like cognosinsight.msi or performancemodeler.msi ( this files are found in folder \ibm\cognos\tm1_64\webapps\pmpsvc\rcp_installs\ on the TM1 server)

 

foreach ($msifile in $msi)

Will process the code block below for each file in the list.

 

Start-Process -FilePath “$env:systemroot\system32\msiexec.exe” -ArgumentList $para0, $msifile , $para1, $para2, $para3 , $para4 -Wait -WorkingDirectory $CurrentLocation

Start-process will call the EXE file and start it with the parameters added ( $para1) and so one. The -workingdirectory is where they will be run, so the $currentlocation should be the folder where the MSI files are stored on the local workstation.

Parameters are separated with comma, and can be any number that the exe file supports.

In our case the second parameter is the name of the MSI file to install, so all parameters after the $smifile parameter, are parameters that is for the MSI file.

 

Hopefully can you improve this script to make it work for your organization.

A other way to run the install in power shell could be with this command

Invoke-Command -ComputerName $computer -ScriptBlock { & cmd /c “msiexec.exe /i c:\download\cognos\cognosrcp.msi” /qn ADVANCED_OPTIONS=1 CHANNEL=100}

A way of populate the variable with current location would be this command

$CurrentLocation = Split-Path -Parent $MyInvocation.MyCommand.Path;

A other way to run the install without parameters more than msi file name is command

Start-Process -FilePath “$env:systemroot\system32\msiexec.exe” -ArgumentList “/i `”$msifile`” /qn /passive” -Wait -WorkingDirectory $CurrentLocation

 

To debug the variables, you can show them in power shell editor by remove remark for this line

## write-host is for debug to show result of variable in powershell-ise

write-host “$env:systemroot\system32\msiexec.exe” -ArgumentList $para0, $msifile , $para1, $para2, $para3 , $para4 -Wait -WorkingDirectory $CurrentLocation

write-host is command to display text and variables on screen.

power shell can be case sensitive in the commands, you need to pay attention to the small caps.

 

More Information

http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/aa367559%28v=vs.85%29.aspx