Solved

Convert this to batch to powershell

Posted on 2016-08-25
5
54 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Set OWA language and time zone in Exchange for individuals, all users or per database.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now