I'm deep into a rabbit hole of why a simple powershell script (below) works via the ISE, but fails when run via InstallShield's Powershell custom action type.
I'm posting the InstallShield-ready version of the script. Trace-Info
can be replaced with Write-Host
and Set-Property
can be commented out.
try
{
Import-Module ActiveDirectory
$all_gmsa_accts = Get-ADServiceAccount -Filter '*'
$valid_gmsa_accts = @( )
ForEach ($acct in $all_gmsa_accts) {
Trace-Info -LogMessage "Checking if account $($acct.Name) can be used on this machine"
if(Test-ADServiceAccount -Identity $acct.Name -WarningAction silentlyContinue) {
$valid_gmsa_accts += $acct.Name
}
}
$prop_value = $valid_gmsa_accts -join ','
$prop_name = "MANAGEDSERVICEACCOUNTS"
Set-Property -Name $prop_name -Value $prop_value
}
catch {
Trace-Info -LogMessage "Exception:"
Trace-Info -LogMessage $_.Exception.Message
}
When I run on either PS command line or PS ISE, I get expected results:
PS D:\ps> .\get-mgmd-test.ps1
Checking if account gmsauser1 can be used on this machine
Checking if account gmsauser2 can be used on this machine
Checking if account cantuseme can be used on this machine
Checking if account tsrcsvcuser1 can be used on this machine
Checking if account tsrcsvcuser2 can be used on this machine
Checking if account tsrcsvcuser3 can be used on this machine
Checking if account tsrcsvcuser4 can be used on this machine
Checking if account tsrcsvcuser5 can be used on this machine
When run from InstallShield, I get the below error messages in the log output.
Action start 11:34:42: GetManagedServiceAccounts.
MSI (c) (64:E8) [11:34:42:266]: Invoking remote custom action. DLL: C:\Users\ADMINI~1\AppData\Local\Temp\MSI9B2D.tmp, Entrypoint: m2
InstallShield: Attempting to load through CLR 4 APIs...
InstallShield: Getting meta host...
InstallShield: Enumerating available runtimes...
InstallShield: Highest available runtime: v4.0.30319
InstallShield: Trying to use highest runtime...
InstallShield: Using highest version runtime...
InstallShield: Loading assembly ClrPsHelper from resource 4097
InstallShield: Calling method with parameters [(System.UInt32)165, (System.String)C:\Users\administrator\AppData\Local\Temp\d397fb4e-db0a-445a-9dc8-7ee4520e6436\getmanagedsvcaccts.ps1]
PowerShell wrapper: Exception:
PowerShell wrapper: Could not load file or assembly 'Microsoft.ActiveDirectory.Management' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
Action ended 11:34:44: GetManagedServiceAccounts. Return value 1.
- So, does anyone have insight into the specific mechanics of the InstallShield powershell CA type shim(s)?
- Why would it be trying to load
Microsoft.ActiveDirectory.Management
when the ISE does not? - Is there some way I can get the PS command line to function in the same profile as
msiexec
?