?
Solved

Convert this to batch to powershell

Posted on 2016-08-25
5
Medium Priority
?
79 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 2000 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

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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