Solved

Convert this to batch to powershell

Posted on 2016-08-25
5
59 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
  • 3
  • 2
5 Comments
 
LVL 83

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 83

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 83

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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