Skip to content

[Bug] Powershell constrained language mode issue when using invoke-AppDeployToolkit.exe #1372

@TomDegreef

Description

@TomDegreef

Prerequisites

PSAppDeployToolkit version

4.0.4

Describe the bug

When running invoke-AppDeployToolkit.exe in an environment that has Powershell constrained language mode enabled (in my case due to WDAC being enabled) , we run into a dot sourcing error.

According to the logs, invoke-AppDeployToolkit.exe adds some parameters to the invoke-AppDeployToolkit.ps1 automatically and that's where the issue lies.

in the logfile snippet we can see the following :

Commencing invocation of C:\WINDOWS\ccmcache\7\Invoke-AppDeployToolkit.ps1.
Administrator rights are required. The verb 'RunAs' will be used with the invocation.
No '-File' parameter specified on command-line. Adding parameter '-File "C:\WINDOWS\ccmcache\7\Invoke-AppDeployToolkit.ps1"'...

Using the -file parameter while having a [cmdletbinding] section, the launch method uses dot sourcing and this is being blocked by WDAC.
Unfortunately this is not truly visible in any of the eventlogs but enabling powershell transcript logging does show you the actual error :

PS>C:\WINDOWS\ccmcache\7\Invoke-AppDeployToolkit.ps1
Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator.
C:\WINDOWS\ccmcache\7\Invoke-AppDeployToolkit.ps1 : Cannot dot-source this command because it was defined in a
different language mode. To invoke this command without importing its contents, omit the '.' operator.
    + CategoryInfo          : InvalidOperation: (:) [Invoke-AppDeployToolkit.ps1], NotSupportedException
    + FullyQualifiedErrorId : DotSourceNotSupported,Invoke-AppDeployToolkit.ps1

A quick fix could be by removing the -File parameter.

Steps to reproduce

  1. Enable Powershell Constrained language mode
  2. Install a PSADTv4 package using Invoke-AppDeployToolkit.exe without any additional parameters.

Environment data

OsName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsProductName   : Windows 10 Enterprise
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}
KeyboardLayout       : 00020409
TimeZone             : (UTC+01:00) Brussels, Copenhagen, Madrid, Paris
HyperVisorPresent    : True
CsPartOfDomain       : True
CsPCSystemType       : Desktop

Metadata

Metadata

Assignees

Labels

Status: Needs TriageNeeds to be labelled and assigned for reviewType: Issue / BugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions