Solved

Convert this to batch to powershell

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

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:oBdA
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

15 Experts available now in Live!

Get 1:1 Help Now