Closed wrighbr closed 5 years ago
Try with latest PR #34.
Still getting the below error msg.
[localhost] Connecting to remote server localhost failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
Also tried running the command without the ComputerName parameter
Invoke-CommandAs -ScriptBlock $script -AsUser $Credential
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.3\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.3\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.3\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.3\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.3\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.3\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.3\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.3\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.3\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:
3.1.4 has been publish to the gallery. This should work now.
Seems to work better but I can't ran a script with elevated rights on the localhost.
@wrighbr this is related to another issue #30 I fixed that one too just now #35
Getting access denied when running using invoke-commandas on the localhost see info below. the credential that I'm using has local admin rights.
PSVersion 5.1.14409.1018 Invoke-CommandAS 3.1.2
$cred = Get-Credential $ScriptBlock = {dir}
Invoke-CommandAs -ScriptBlock $ScriptBlock -ComputerName localhost -Credential $cred -AsUser $cred
[localhost] Connecting to remote server localhost failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.