GithubHelp home page GithubHelp logo

Comments (6)

skille avatar skille commented on June 29, 2024 1

I tested now again, unable to provoke the error, but still, the code does not run.
Import-Module -Name Invoke-CommandAs
$Credential = Get-Credential
$Server = 'ServerName'
Invoke-CommandAs -ComputerName $Server -AsSystem -ArgumentList $Credential -ScriptBlock {
param ($Credential)
$Credential.UserName
}
The username is not returned

This also returns nothing;
Invoke-CommandAs -ComputerName $Server -AsSystem -ArgumentList $Credential -ScriptBlock {
param ($Credential)
Test-Path -Path $env:TEMP
}

Removing the argument returns True as expected.
Invoke-CommandAs -ComputerName $Server -AsSystem -ScriptBlock {
Test-Path -Path $env:TEMP
}

Looking besides this issue, I must say you have done an impressive job with this module!

from invoke-commandas.

mkellerman avatar mkellerman commented on June 29, 2024

Please provide an example of the code you are executing.

from invoke-commandas.

mkellerman avatar mkellerman commented on June 29, 2024

You can pass credential parameter inside this scriptblock.. too much inceptions.. lol rename it to $cred or something

from invoke-commandas.

skille avatar skille commented on June 29, 2024

ffs! Thanks a lot ! ;)
`Invoke-CommandAs -ComputerName $server -ArgumentList $Credential -ScriptBlock {

param($Cred)
$Cred.username
test-path $env:temp
}
`
Now returning both the username and True :)

Have a nice day :)

from invoke-commandas.

skille avatar skille commented on June 29, 2024

Actually, I tested wrong when I closed the case.
I forgot to add the -AsSystem switch. Adding it returns nothing.
Invoke-CommandAs -ComputerName $ServerName -ArgumentList $Credential -AsSystem -ScriptBlock {
param($Cred)
$Cred.username
test-path $env:temp
}

from invoke-commandas.

skille avatar skille commented on June 29, 2024

I worked around this problem by converting the credential objects to an base64 encoded string and back.
`
$Base64Credential = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((@{
UserName = $Credential.UserName
Password = $Credential.GetNetworkCredential().Password
} | ConvertTo-Json)))

Invoke-CommandAs -ComputerName $ServerName -AsSystem -ArgumentList $Base64Credential -ScriptBlock {
param(
$Base64Credential
)
$Credential = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64Credential)) | ConvertFrom-Json
$Credential = New-Object -TypeName PScredential -ArgumentList $Credential.UserName,$(ConvertTo-SecureString -String $Credential.Password -AsPlainText -Force)

$Credential

}
`

from invoke-commandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.