Tuesday, September 6, 2016

Using SysNative to redirect a SCCM Package to use 64-Bit stuff...

Everywhere you go it seems like all the "experts" say to use the Package model (not the Application model) when you want to deploy a script using SCCM. The problem is Packages seem to only be be cable of executing in 32 bit mode (even on 64_bit OSes) because the SCCM client is 32-Bit. Obviously this presents a problem if you ever need to have your script reference anything 64-bit. I did some googling and found a number of solutions out there but (ultimately) found them a bit clunky. So I grabbed the best bits I could found out of all of them and combined them into my own script:

@ECHO OFF & CLS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: SysNative Redirect :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Purpose: SysNative is a virtual folder visible to 32-Bit applications but not :: visible to 64-Bit applications. This script uses SysNative to redirect scripts :: to use native executables on when run on a 64-Bit Operating System. :: Version: 2.1 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: REM Set script filename: SET "_MyScript=%~n0.ps1" REM OS Run architecture check and redirect if needed: If "%PROCESSOR_ARCHITEW6432%"=="" (GOTO :_STANDARD) ELSE (GOTO :_SYSNATIVE) :_SYSNATIVE %WINDIR%\sysnative\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass -file "%~dp0%_MyScript%" REM %WINDIR%\sysnative\cscript.exe "%~dp0myscript.vbs" REM %WINDIR%\sysnative\cmd.exe "%~dp0myscript.cmd" GOTO :_END :_STANDARD powershell.exe -NoProfile -ExecutionPolicy bypass -File "%~dp0%_MyScript%" REM cscript.exe "%~dp0myscript.vbs" REM cmd.exe "%~dp0myscript.cmd" GOTO :_END :_END REM Pause to view results: REM ECHO. REM ECHO Press any key to exit ... REM PAUSE > NUL

To use it just uncomment your script language of choice (while commenting out the ones you don't want), save it as a .CMD file in the same folder with the same name as the script you want to execute and specify the .CMD file as your Command Line. It should handle the rest for you.

No comments:

Post a Comment