Comments (7)
$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.
above is the basic wmi remote method of executing powershell remotely
from invoke-commandas.
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.
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.
https://github.com/mkellerman/Invoke-CommandAs/tree/mk-feature-wmicommand
Let me know if this works for you! Obviously, there is no output... :(
from invoke-commandas.
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.
Closed. Please re-open ticket if you have any issues.
from invoke-commandas.
Related Issues (20)
- Removal of RunElevated Parameter HOT 3
- Access is denied. on localhost HOT 6
- Unable to invoke command as gMSA - v3.1.2 HOT 11
- Access Denied with -RunElevated HOT 3
- AsUser Doesn't Impersonate user HOT 9
- Removing entries from the Task Scheduler log HOT 3
- $Using: variable preface not respected HOT 6
- Module on Powershell Core HOT 2
- Erro running RunElevated parameter HOT 4
- Support for PowerShell 7 HOT 11
- PowerShell Core Compatiblility HOT 2
- Not working when using variables in script block HOT 3
- Can't figure out the right amount of permission HOT 2
- Unable to submit credential objects as arguments HOT 6
- AsSystem doesn't seem to execute while device is on battery power HOT 4
- Would it be possible to run -AsLocalService
- Invoke-CommandAs -AsSystem broke on 2012 R2 ENG
- Add support for Network Service HOT 1
- Add tagging to Azure pipeline for releases HOT 2
- parsing error when using -FilePath HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invoke-commandas.