Jump to content

Recommended Posts

Posted (edited)

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

  Reveal hidden contents

 

  • Moderators
Posted

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!

Posted

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

  Reveal hidden contents

 

Posted

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)

 

  Reveal hidden contents

Posted

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

  Reveal hidden contents

 

  • 2 weeks later...
Posted

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

  Reveal hidden contents

 

Posted

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

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

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

  Reveal hidden contents

 

Posted

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")

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

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

  Reveal hidden contents

 

Posted

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

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

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
  • Recently Browsing   0 members

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