Solved

Convert this to batch to powershell

Posted on 2016-08-25
5
76 Views
Last Modified: 2016-09-02
Currently I can run this script and it can tell me that if it is windows 32 or 64 bit.  Can you tell me how to convert to powershell

 
IF EXIST "C:\Program Files (x86)\" ( GOTO OS64 ) ELSE ( GOTO OS32 )

:OS32
QBP.msi /quiet
GOTO ENDA

:OS64
QBP64.msi /quiet

:ENDA
EXIT

Open in new window



Then when it defines what OS I am going to call on

$Source = "http://source.QBP.msi"
$FileName = Split-Path $Source -Leaf
$Destination = "C:\Temp\$($FileName)"
$Description = "$FileName Download"
$DisplayName = "$FileName Download"

$Job = Start-BitsTransfer -Asynchronous -TransferType Download -Priority Foreground -Description $Description -DisplayName $DisplayName -Destination $Destination -Source $Source
Get-BitsTransfer -JobId $Job.JobId

Open in new window


There will be a call and then I want it to also install the msi depending upon if it is 32bit or 64bit msi.
0
Comment
Question by:sj77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 41770321
This sets $msi to the correct name:
$msi = If ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq '64-bit') {'QBP64.msi'} else {'QBP.msi'}

Open in new window

1
 

Author Comment

by:sj77
ID: 41770329
So i realize that what I am really wanting is if 32 bit or 64 bit then I need it to download a certain file and then run it.

So how would you write that script?
0
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 41770348
You can use something like this:
$msi = If ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq '64-bit') {'QBP64.msi'} else {'QBP.msi'} 
Invoke-WebRequest -Uri "http://domain.com/$($msi)" -OutFile "C:\Temp\$($msi)"
msiexec.exe /i "C:\Temp\$($msi)"

Open in new window

0
 

Author Comment

by:sj77
ID: 41770380
oBdA,

I would like to use BitsTransferr about this so would it look like this,

$msi = If ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq '64-bit') {'QBP64.msi'} else {'QBP.msi'} 
Invoke-WebRequest -Uri "http://domain.com/$($msi)" -OutFile "C:\Temp\$($msi)"
$Job = Start-BitsTransfer -Asynchronous -TransferType Download -Priority Foreground -Description $Description -DisplayName $DisplayName -Destination $Destination -Source $Source
Get-BitsTransfer -JobId $Job.JobId

msiexec.exe /i "C:\Temp\$($msi)"

Open in new window

0
 
LVL 85

Expert Comment

by:oBdA
ID: 41770409
If you're using BitsTransfer, you obviously don't need the Invoke-WebRequest, though I don't see any gains.
And if you're running it asynchronous (why?), you need to take care of the waiting until the file is arrived yourself; Get-BitsTransfer doesn't do that. msiexec then obviously needs to be started with $Destination, not with $msi.
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question