通过 AutoHotKey 脚本运行 powershell 命令

sam*_*da1 4 powershell scripting autohotkey

我希望能够通过 AutoHotKey 脚本运行以下 PowerShell 命令:

new-item -path c:\ -name logfiles -itemtype directory
Run Code Online (Sandbox Code Playgroud)

我无法找到完成此任务的方法。请帮忙。

小智 8

如果你想从 ahk 运行一个 PowerShell 脚本并且它包含多行并且你不想使用外部文件,这是一个如何做的例子:

自动热键代码:

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%'   
Run Code Online (Sandbox Code Playgroud)


err*_*ven 2

尝试:

Run, PowerShell "new-item -path c:\ -name logfiles -itemtype"
Run Code Online (Sandbox Code Playgroud)

似乎对我有用。

根据新提供的信息进行编辑:

命令找到@ http://exchangeserverpro.com/install-exchange-2013-pre-requirements-windows-server-2012/

尝试:

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"
Run Code Online (Sandbox Code Playgroud)