Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a powershell command through AutoHotKey script

I want to be able to run a following PowerShell command through AutoHotKey script:

new-item -path c:\ -name logfiles -itemtype directory

I am unable to find a way to achieve this task. Please help.

like image 871
samisda1 Avatar asked Dec 25 '22 14:12

samisda1


2 Answers

If you want to run a PowerShell script from ahk and it contains several lines and you don't want to use an external file, this is an example how do it:

AutoHotkey code:

psScript =
(
    param($param1, $param2)

    new-item -path $param1 -name logfiles -itemtype directory
    new-item -path $param2 -name logfiles -itemtype directory
    remove-item -path 'c:\temp'
    # etc, write any code, use this quotes for strings: '
    # if you need ", then write: \":
    $import = '[DllImport(\"ntdll.dll\")] public static extern int RtlAdjustPrivilege(ulong a, bool b, bool c, ref bool d);'
)

param1 = C:\temp
param2 = D:\temp

RunWait PowerShell.exe -Command &{%psScript%} '%param1%' '%param2%',, hide

; use this call if you want to see powershell output
Run PowerShell.exe -NoExit -Command &{%psScript%} '%param1%' '%param2%'   
like image 161
Argimko Avatar answered Dec 28 '22 07:12

Argimko


Try:

Run, PowerShell "new-item -path c:\ -name logfiles -itemtype"

Seemed to work for me.

Edit based on newly provided information:

Command found @ http://exchangeserverpro.com/install-exchange-2013-pre-requisites-windows-server-2012/

Try:

Run, PowerShell "Install-WindowsFeature AS-HTTP-Activation
                , Desktop-Experience
                , NET-Framework-45-Features
                , RPC-over-HTTP-proxy
                , RSAT-Clustering
                , Web-Mgmt-Console
                , WAS-Process-Model
                , Web-Asp-Net45
                , Web-Basic-Auth
                , Web-Client-Auth
                , Web-Digest-Auth
                , Web-Dir-Browsing
                , Web-Dyn-Compression
                , Web-Http-Errors
                , Web-Http-Logging
                , Web-Http-Redirect
                , Web-Http-Tracing
                , Web-ISAPI-Ext
                , Web-ISAPI-Filter
                , Web-Lgcy-Mgmt-Console
                , Web-Metabase
                , Web-Mgmt-Console
                , Web-Mgmt-Service
                , Web-Net-Ext45
                , Web-Request-Monitor
                , Web-Server
                , Web-Stat-Compression
                , Web-Static-Content
                , Web-Windows-Auth
                , Web-WMI
                , Windows-Identity-Foundation"
like image 41
errorseven Avatar answered Dec 28 '22 07:12

errorseven