Showing posts with label batch file. Show all posts
Showing posts with label batch file. Show all posts

Sunday, 12 July 2015

Using PowerShell To Check The OS Architecture

This post was actually inspired by the previous post: 


I was thinking using Powershell instead, the previous batch file serves the purpose, check for that particular folder and wah la you got your program installed. But I want to tap on Powershell's advance feature to ensure that the machine is really on 64 bit OS to install. 

So here goes: 

$OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture -ErrorAction Stop).OSArchitecture
if ($OSArchitecture -eq '64-bit')
{& path:\a.exe}
else
{& path:\b.exe}

The idea is to use Powershell to check on the OS architecture. The strings behind Win32_OperatingSystem can be found here

You will need to change the variable yourself for the software path. 

Afterwards you can deploy the a batch file to invoke the above Powershell script to install the programs. Make sure you add in the required installation parameters as well. 

In case you do not know how to use a batch file to run Powershell scripts you can take a look of my previous posts on simple scripting to get the job done: 




Enjoy!

SY

Wednesday, 1 July 2015

Using Batch File To Check The OS Architecture

Today is a interesting day, whereby client wanted to deploy 2 versions Java (32 and 64 bits) to client machines.


One of the easier method is to use "Platform requirements" under Package:







and the other deployment method, choose "Requirements" under Application deployment to allow the package to detect the OS architecture of the client to install the appropriate version of the software.


The above method works fine, if you deploy just a 32 bit application, or you could exclude the OS versions. But you what if you have specific requirements that you need to deploy the 32 and 64 bits applications to respective OS? Well you could deploy two times or you use the following batch file to deploy: 

=====================================
@echo off
SET LogLoc=C:\LOGS
SET AppName=JAVA83_Install

IF NOT EXIST "%LogLoc%" (
MKDIR "%LogLoc%"
ECHO %DATE% %TIME% - %LogLoc% created >> %LogLoc%\%AppName%.log
) ELSE (
ECHO %DATE% %TIME% - %AppName% started >> %LogLoc%\%AppName%.log
)

IF EXIST "C:\Program Files (x86)" ("amd64/03-Java83.exe" /s) else ("x86/03-Java83.exe" /s)

ECHO %DATE% %TIME% - checking processor architecture - %CPUArch% >> %LogLoc%\%AppName%.log
ECHO %DATE% %TIME% - Starting JAVA 8 U31 Installation on %computername% >> %LogLoc%\%AppName%.log
SET ErrorCode=%ERRORLEVEL%
ECHO %DATE% %TIME% - Exit Code is - %ErrorCode% >> %LogLoc%\%AppName%.log
ECHO %DATE% %TIME% - Exiting Installation >> %LogLoc%\%AppName%.log
Exit %ErrorCode%

pause

=====================================

Copy and paste the above batch command, save as "CMD" or "BAT" . Change the files location and application name on the highlighted portion and deploy it under "Package" and you are good to go. 

This lead me to think, can I use Powershell to achieve it instead? :) 

Give you guys a update soon, hope you guys like it. 

Have fun. 

SY


Thursday, 23 April 2015

Clear CCMCache Contents

Re-editing this old post from former blog, you could deploy it as a batch file to your SSP (Self-Service Portal) in SCCM Application Catalog page and allow the user to clear the content on their own instead of:



Here is the PS command, I added a "Force" parameter to it: 

#Removes the contents of CCMCACHE folder 

Remove-Item -Path C:\Windows\CCMCahce\* -Force -Recurse

Save the above PS commands as XXXX.PS1

The batch file that is required to run the above PS command: 

@ECHO OFF
SET PSScriptDir=%~dp0
SET PSScriptPath=%PSScriptDir%RemoveCCMCacheContents.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PSScriptPath%'";
pause

Make sure you save the above as XXXX.CMD

Save both files in the same directory (Less than 3KB) and you are ready to go!

Have Fun :) 

SY