Jump to content

[Solved]Powershell commands


caramen
 Share

Recommended Posts

Hello guys.

I whould like to do that with autoit :

ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe")
Sleep (500)
Send ("Get-ADUser sdr**x -Properties OfficePhone | Select -Expand OfficePhone")
Send("{ENTER}")

Is there way to do that with autoit without exit of my script

 

I whould like to get the return value of the executed command in a autoit variable

 

something like :

$A = ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe")
Sleep (500)
Send ("Get-ADUser sdr**x -Properties OfficePhone | Select -Expand OfficePhone")
Send("{ENTER}")

 

I am introducing myself in powershell things so.. i ve not got much skills in it. (So any idea is welcome :) )

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Moderators

Just a question, since you can get all of that information and return it through AutoIt, why the need to mix languages? Either stick solely with PS and output to a grid-view, or use the A.D. UDF in AutoIt and output as you see fit.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Because it s my first script that gonna tuch the active directory directly. i am not familiar with that so i had no idea.

 

Ty i am gonna look today.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I cant let you run powershell commands like that, try something like this:

#include<array.au3>

$iPid = run('powershell Get-ADUser sdr**x -Properties OfficePhone | Select -Expand OfficePhone'  , @WindowsDir , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
 WEnd

;~ msgbox(0, '' , $sOutput)

$aOutput = stringsplit($sOutput , @LF , 2)
_ArrayDisplay($aOutput)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

The two solutions provided are perfect for me.

Work like a charm.

 

 

Thx to both of you. :).

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello guys I was coding my script using the IamTheKy technique because it s the best technique for what i need.

 

But i have a problem

If i change the powershell command i dont get anymore the wanthed return value

 

i show you the code*

$Username = InputBox("Atol", "Entrer un LOGIN svp", "LOGIN", "")


ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe")
Sleep (500)
Send ("Get-ADUser " &$Username &" | select -Expand Name")
Send("{ENTER}")


$iPid = run("Get-ADUser " &$Username &" | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
 WEnd

msgbox(0, '' , $sOutput)

$aOutput = stringsplit($sOutput , @LF , 2)

;~ _ArrayDisplay($aOutput)
;~ msgbox(0, '' , $sOutput)

WinClose ("Windows PowerShell")

*

This one work perfectly

$Username = InputBox("Atol", "Entrer un LOGIN svp", "LOGIN", "")


ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe")
Sleep (500)
Send ("Get-ADUser "&$Username&" -Properties OfficePhone | Select -Expand OfficePhone")
Send("{ENTER}")


$iPid = run('powershell Get-ADUser '&$Username&' -Properties OfficePhone | Select -Expand OfficePhone'  , @WindowsDir , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
 WEnd

msgbox(0, '' , $sOutput)

$aOutput = stringsplit($sOutput , @LF , 2)

;~ _ArrayDisplay($aOutput)
;~ msgbox(0, '' , $sOutput)

WinClose ("Windows PowerShell")

If i change to

$Username = InputBox("Atol", "Entrer un LOGIN svp", "LOGIN", "")


ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe")
Sleep (500)
Send ("Get-ADUser " &$Username &" | select -Expand Name")
Send("{ENTER}")


$iPid = run("Get-ADUser " &$Username &" | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
 WEnd

msgbox(0, '' , $sOutput)

$aOutput = stringsplit($sOutput , @LF , 2)

;~ _ArrayDisplay($aOutput)
;~ msgbox(0, '' , $sOutput)

WinClose ("Windows PowerShell")

The returned valu is now empty

 

Can i got explanation so i dont come here to ask why at each commands i whould like to understand and not only copy past what i have as an help.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

With as many posts as you have, it shouldn't be hard for you to see each cmd you don't know in the help file.

I don't know powershell, but It seems to me that you have a extra '|' in

Send ("Get-ADUser " &$Username &" | select -Expand Name")

But i may be wrong, it just looks out of place

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You are rigth lol.

But for myself it s false^^.

 

I always look the helpfile before post anything here and also Search for similar post before ask.

 

 

Second thing i post my code with a $VARIABLE

But for testing i use the command without a variable

 

Exemple for me :

*

Send ("Get-ADUser jpersonal | select -Expand Name")

and it's working in powershell i have the return value : Jordane Personal

I just want to store it in a autoit variable as $Username

 

Everything is fine wwith the first code but it s not working anymore if i change the powershelle command

 

 

EDIT : Btw the extra '|' in my command is for filtering information in AD

without it the command does not work at all.

 

It s the same as doing ipconfig /all without the /

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Im confused

$Username = InputBox("Atol", "Entrer un LOGIN svp", "LOGIN", "")


ShellExecute ("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe") ;Start powershell
Sleep (500)
Send ("Get-ADUser " &$Username &" | select -Expand Name")  ;Write your command with the profile from the inputbox
Send("{ENTER}")


$iPid = run("Get-ADUser " &$Username &" | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2) ;Run... a command without any exe. :|

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID) ;Read console output
        If @error Then
            ExitLoop
        EndIf
 WEnd

msgbox(0, '' , $sOutput) ;show output

$aOutput = stringsplit($sOutput , @LF , 2) ;split result in all @LF but don't use the splitted result for anything

;~ _ArrayDisplay($aOutput)
;~ msgbox(0, '' , $sOutput)

WinClose ("Windows PowerShell")

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

hahahah you just gifted me the solution i am explaining :

 

I had the purpose of getting multiple informations with powershell command for automatig a loooooot of thing in a software developed with autoit.

 

I dont want to split language in the same script so i find the solution i am using perfect for me.

 

So you are confused about the code becose the guy just showed to me how to use multiple way the command he provided to me. that was so nice from him.

 

Now with your comment :

$iPid = run("Get-ADUser " &$Username &" | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2) ;Run... a command without any exe. :|

you made me understand i was sending a command in "nothing" haha i iam stupid.

 

But like that :

$iPid = run("powershell Get-ADUser jpersonal | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2)

It s working.... damn i am so stupid.

 

Thank bro you saved my time today :D have a good day.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Ok, i ended up condensing it a bit, but seeing as you solved it, it's all good XD

#include <Array.au3>

$Username = InputBox("Atol", "Entrer un LOGIN svp", "LOGIN", "")

$iPid = run("powershell Get-ADUser " &$Username &" | select -Expand Name"  , @WindowsDir , @SW_HIDE , 0x2)
$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        Else
            $aOutput = stringsplit($sOutput , @LF , 2)
            _ArrayDisplay($aOutput)
            ProcessClose($iPid)
        EndIf
 WEnd

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...