Is there a way to work with powershell objects in Autohotkey? convert them to ahkobjects?
Has someone seen some code or has an idea how to do?
powershell objects to Autohotkey
Re: powershell objects to Autohotkey
If you mean PowerShell cmdlets then it's very easy to wrap them in AHK.
For example:
I use this to refresh the Windows desktop.
It's also fairly easy to build queries and redirect output, for example:
Hope this helps...
For example:
Code: Select all
psScript =
(
Stop-Process -ProcessName explorer
)
Run PowerShell.exe -Command %psScript%,, hide
It's also fairly easy to build queries and redirect output, for example:
Code: Select all
psScript =
(
Get-NetTCPConnection | ? State -eq 'Established' | ? RemoteAddress -notlike 127* | FT -Autosize | Out-File C:\Support\established-connections.txt
)
; Use this call if you *don't* want to see PowerShell output
RunWait PowerShell.exe -Command %psScript%,, hide
; Use this call if you want to see PowerShell output
; Run powershell.exe -NoExit -Command %psScript%
Run, C:\Support\established-connections.txt
ExitApp
Re: powershell objects to Autohotkey
Thank you very much! I found a slightly different solution:
Code: Select all
#include json.ahk ;https://github.com/cocobelgica/AutoHotkey-JSON
ps=Get-Service "s*" | Where-Object {$_.Status -eq 'running'} | Sort-Object status -Descending
svc:=RunPS(ps)
loop, 5
msgbox, % svc[a_index].name
return
RunPS(ps) {
json_str:=ComObjCreate("WScript.Shell").Exec("powershell -command " ps " | ConvertTo-Json").StdOut.ReadAll() ;convert a Powershellobject to a json-string
return JSON.Load(json_str) ;returns an AHK-Object
}
Re: powershell objects to Autohotkey
I've tried the posted RunPS() function by passing Get-Process likehaichenatwork wrote: ↑27 Feb 2018, 03:45Thank you very much! I found a slightly different solution:
Code: Select all
#include json.ahk ;https://github.com/cocobelgica/AutoHotkey-JSON ps=Get-Service "s*" | Where-Object {$_.Status -eq 'running'} | Sort-Object status -Descending svc:=RunPS(ps) loop, 5 msgbox, % svc[a_index].name return RunPS(ps) { json_str:=ComObjCreate("WScript.Shell").Exec("powershell -command " ps " | ConvertTo-Json").StdOut.ReadAll() ;convert a Powershellobject to a json-string return JSON.Load(json_str) ;returns an AHK-Object }
Code: Select all
RunPS( "Get-Process" )
Who is online
Users browsing this forum: Google [Bot] and 124 guests