GithubHelp home page GithubHelp logo

Comments (7)

WinOpsEngineer avatar WinOpsEngineer commented on June 25, 2024 1

$commandBytes = [System.Text.Encoding]::Unicode.GetBytes($ScriptBlock)
$encoded = [Convert]::ToBase64String($commandBytes)
$command = "powershell -NoProfile -EncodedCommand $encoded"
$null = Invoke-WmiMethod -Computer $computername -Credential $Credential Win32_Process Create -Args $command

from invoke-commandas.

WinOpsEngineer avatar WinOpsEngineer commented on June 25, 2024 1

above is the basic wmi remote method of executing powershell remotely

from invoke-commandas.

mkellerman avatar mkellerman commented on June 25, 2024

Invoke-CommandAs -AsWmiMethod ?

This might need to be implement as a whole separate function. As Iā€™d want to replicate all the Invoke-WmiMethod parameters, simply adding -AsSystem, -AsCredential and -AsGSMA

Invoke-WmiMethodAs ?

from invoke-commandas.

mkellerman avatar mkellerman commented on June 25, 2024

After playing around with the code, I think this might need to be it's own module.

the expectation, is to convert the Invoke-Command, into a Invoke-Command[As], adding a few custom parameters to the regular Invoke-Command function.

Will need to investigate more how this could be implemented. Please take a look at the private function Invoke-ScheduledTask, to help you accelerate some of your functionality.

I'd be open to start a new project, and get the structure going on if you'd want to help out?

For now, I'll close the issue, please DM me on twitter.. ;)

from invoke-commandas.

mkellerman avatar mkellerman commented on June 25, 2024

https://github.com/mkellerman/Invoke-CommandAs/tree/mk-feature-wmicommand

image

Let me know if this works for you! Obviously, there is no output... :(

from invoke-commandas.

mkellerman avatar mkellerman commented on June 25, 2024

Quick and dirty way to see if it works:

$ComputerName = 'W2012R2'
$Credential = Get-Credential 'Administrator'

$ScriptBlock = {

    New-Item -Path C:\Temp -ItemType Directory -Force | Out-Null
    [System.Security.Principal.Windowsidentity]::GetCurrent() | Out-File "C:\Temp\pwsh_output.txt"

}

$WmiProcess = Invoke-WmiCommandAs -ScriptBlock $ScriptBlock -ComputerName $ComputerName -Credential $Credential -AsSystem

While (Get-WmiObject -Class 'Win32_Process' -Filter "ProcessId='$($WmiProcess.ProcessId)'" -ComputerName $ComputerName -Credential $Credential -EA 0) {
    Write-Warning "$(Get-Date): Waiting..."
    Start-Sleep -Milliseconds 200
}

Then go check the content of the file at: C:\Temp\pwsh_output.txt

from invoke-commandas.

mkellerman avatar mkellerman commented on June 25, 2024

Closed. Please re-open ticket if you have any issues.

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.