Forum Discussion
Cannot dot-source this command because it was defined in a different language mode.
I'm rather surprised to hear there were no relevant events within the AppLocker\MSI and Script node as that's a common reporting point for both AppLocker and Windows Defender Application Control (WDAC). That also leaves me a little short on other ideas, since it sounds like it's being set outside of policy.
In no particular order, here's some thoughts:
- ConstrainedLanguage mode is the only language option on ARM/Windows RT platforms:
about Language Modes - PowerShell | Microsoft Learn - Check any relevant PowerShell profiles to ensure ConstrainedLanguage hasn't been assigned somewhere within:
about Profiles - PowerShell | Microsoft Learn - Ensure your virus scanner isn't perhaps preventing those __PSScript .ps1 and .psm1 files from executing;
- Finally, I've quickly put together a "hack" script that collects some meaningful information in relation to WDAC. It isn't very granular as it's only intended to help identify which areas could use further exploration.
Get-WDACInfo.ps1
#region Preamble.
# We're only interesting in testing against Windows 10 or later.
$NTBuildString = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Version -ErrorAction:Stop).Version;
$NTBuildParts = $NTBuildString.Split(".");
$NTMajorVersion = $NTBuildParts[0].ToInt32($null);
if ($NTMajorVersion -lt 10)
{
throw "This script can only be run on Windows 10 or later.";
}
# Since we're already checking versions, see if we're on Windows 10 1903 or later.
$IsLegacy = $false;
if (($NTMajorVersion -eq 10) -and ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "ReleaseId").ReleaseId.ToInt32($null) -lt 1903))
{
$IsLegacy = $true;
}
#endregion
#region AppLocker policy check.
# See if AppLocker group policy enforcement has been applied.
Write-Warning -Message "AppLocker policy enforcement.";
[PSCustomObject] @{
IsAppLockerEXEEnforced = (1 -eq (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Exe" -Name "EnforcementMode" -ErrorAction:SilentlyContinue).EnforcementMode);
IsAppLockerScriptEnforced = (1 -eq (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Script" -Name "EnforcementMode" -ErrorAction:SilentlyContinue).EnforcementMode);
} | Out-Default;
#endregion
#region CI Policy registry data.
Write-Warning -Message "CI Policy registry data.";
Get-ChildItem -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CI\" -Recurse -ErrorAction:SilentlyContinue | Where-Object { ($_.ValueCount -gt 0) -or ($_.SubKeyCount -gt 0) } | Out-Default;
#endregion
#region WDAC policy file(s).
Write-Warning -Message "WDAC policy file detection.";
if ($IsLegacy)
{
[PSCustomObject] @{
IsCIDefined = (Test-Path -Path "C:\Windows\System32\CodeIntegrity\SiPolicy.p7b" -ErrorAction:SilentlyContinue);
IsCIApplied = IsCIDefined;
} | Out-Default;
}
else
{
[PSCustomObject] @{
IsCIDefined = $null -ne (Get-ChildItem -Name -Path "C:\Windows\System32\CodeIntegrity\CiPolicies\*" -Include "*.cip" -Recurse -ErrorAction:SilentlyContinue);
IsCIApplied = $null -ne (Get-ChildItem -Name -Path "C:\Windows\System32\CodeIntegrity\CiPolicies\Active\*" -Include "*.cip" -ErrorAction:SilentlyContinue);
} | Out-Default;
}
#endregion
#region WDAC Event Log stats.
Write-Warning -Message "Relevant Event Log stats.";
$LogNames = @(
"Microsoft-Windows-AppLocker/MSI and Script",
"Microsoft-Windows-CodeIntegrity/Operational"
);
$LogNames | ForEach-Object {
Get-WinEvent -ListLog $_ | Select-Object -Property LogMode, IsEnabled, LogName, RecordCount;
} | Out-Default;
#endregion
From which an example of the output is below.
If either of the settings I've boxed in green have a value of True, policy probably is the cause even if you're not seeing relevant errors in the event logs. If they're both False as mine are, then my best guess is the PowerShell profiles or session configuration file (though I don't see such files commonly used.)
While I'm quite familiar with AppLocker, I'm quite unfamiliar with WDAC, meaning you might also get some mileage on this issue through asking in an InTune forum, too.
The option you'd be asking them about is option 11 from the following table, where if it's coming back with a value of "enabled", then it is not the cause of your problem, where "disabled" would mean it is.
Cheers,
Lain
Thanks All for your help!
I had an internal discussion with my team, and we found that this occurred due to some internal security changes implemented after windows 22H2 update and resolved by following the troubleshooting steps.
- RaviKiranSNov 07, 2022
Microsoft
In my case, its Microsoft Internal tools, agents running with some configs. was the issue. Updating those resolved for me. So, I can't provide those details it to the public.
- prasannamiskinNov 07, 2022Former EmployeeHi RaviKiranS, even I have been facing this issue post 22H2 upgrade and landed up here for a solution, would you be able to share the troubleshooting steps here so that people like me can also be benefited from it?