caramen

[Solved]Powershell commands

11 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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.

Share this post


Link to post
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)

 


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

Share this post


Link to post
Share on other sites

The two solutions provided are perfect for me.

Work like a charm.

 

 

Thx to both of you. :).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

#8 ·  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

Share this post


Link to post
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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

#10 ·  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

Share this post


Link to post
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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
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