Share via


powershell Microsoft.SMS.TSEnvironment

Question

Thursday, November 5, 2015 10:34 AM

Hey,

during OSD Task Sequence I try to run a PowerShell script which is started through command line in a legacy package.

The command line looks like the following because of architecture information I read I tried two):

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& {%~dp0SysInst_Silent.ps1}"

%windir%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& {%~dp0SysInst_Silent.ps1}"

Powershell script is like the following:

$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$name = $TSEnv.Value("OSDComputerName")

Unfortunately the script (when executed form package in TS step) fails in both cases with error:
"Retrieving the COM class factory for component with CLSID {2D26B0A2-A1C9-4E75-84CB-9102F6842FE5} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

When I create a pause step (just open a notepad) during the Task Sequence and run the Script via "F8" it works without any problems like the following:

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& {%~dp0SysInst_Silent.ps1}"

Any Idea where the difference is?

Thanks

All replies (3)

Thursday, November 5, 2015 3:40 PM âś…Answered

No the "%~dp0" was in a batch file :)

I was able to resolve the problem by using the "Run PowerShell Script" step in Task sequence instead of 'Run Command Line" step and call the powershell by batch file..


Thursday, November 5, 2015 2:25 PM

Is that command what you entered in the command line field in the task sequence editor? If so, %~dp0 will not work. . .that is specific to batch scripts. . .

Jeff


Monday, June 6, 2016 2:32 AM

when the 'Run Command Line' step in a Task Sequence add the '-noprofile' to the call, until I added that I could not get the command "$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment" working at all

powershell.exe -noprofile -command "&{<PS code here>}"