I'm currently running into an issue where I'm not able to run a command as a gMSA using v3.1.2 of this module. v3.1.1 works as expected.
I'm seeing this on Windows Server 2019 with Windows PowerShell 5.1.
PS C:\WINDOWS\system32> Import-Module Invoke-CommandAs -RequiredVersion 3.1.2
PS C:\WINDOWS\system32> Invoke-CommandAs -ScriptBlock { Get-Process | Select -First 10 } -AsGMSA 'domain\ManagedServiceAccount$'
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:347 char:21
+ ... $Using:_Function | ForEach-Object { Invoke-Expression $_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:348 char:21
+ ... $Using:_Using | ForEach-Object { Set-Variable -Name $_.Na ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:351 char:25
+ If ($Using:ScriptBlock) { $Parameters['ScriptBl ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:352 char:25
+ If ($Using:ArgumentList) { $Parameters['Argument ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:353 char:25
+ If ($Using:AsUser) { $Parameters['AsUser'] ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:354 char:25
+ If ($Using:AsSystem) { $Parameters['AsSystem ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:355 char:25
+ If ($Using:AsInteractive) { $Parameters['AsIntera ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:356 char:25
+ If ($Using:AsGMSA) { $Parameters['AsGMSA'] ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or
InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the
script block is invoked on a remote computer.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.2\public\Invoke-CommandAs.ps1:357 char:25
+ If ($Using:IsVerbose) { $Parameters['Verbose' ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : UsingWithoutInvokeCommand
cmdlet Invoke-ScheduledTask at command pipeline position 1
Supply values for the following parameters:
ScriptBlock:
Please let me know if I can provide any other info, error dumps, or whatever else.