{"action":"created","issue":{"url":"https://api.github.com/repos/StackStorm/st2/issues/1287","labels_url":"https://api.github.com/repos/StackStorm/st2/issues/1287/labels{/name}","comments_url":"https://api.github.com/repos/StackStorm/st2/issues/1287/comments","events_url":"https://api.github.com/repos/StackStorm/st2/issues/1287/events","html_url":"https://github.com/StackStorm/st2/pull/1287","id":63547652,"number":1287,"title":"[DONT MERGE] [WIP] [EXPERIMENTAL] Windows command and script runner","user":{"login":"Kami","id":125088,"avatar_url":"https://avatars.githubusercontent.com/u/125088?v=3","gravatar_id":"","url":"https://api.github.com/users/Kami","html_url":"https://github.com/Kami","followers_url":"https://api.github.com/users/Kami/followers","following_url":"https://api.github.com/users/Kami/following{/other_user}","gists_url":"https://api.github.com/users/Kami/gists{/gist_id}","starred_url":"https://api.github.com/users/Kami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kami/subscriptions","organizations_url":"https://api.github.com/users/Kami/orgs","repos_url":"https://api.github.com/users/Kami/repos","events_url":"https://api.github.com/users/Kami/events{/privacy}","received_events_url":"https://api.github.com/users/Kami/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-22T16:06:22Z","updated_at":"2015-03-23T02:22:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/StackStorm/st2/pulls/1287","html_url":"https://github.com/StackStorm/st2/pull/1287","diff_url":"https://github.com/StackStorm/st2/pull/1287.diff","patch_url":"https://github.com/StackStorm/st2/pull/1287.patch"},"body":"This pull request adds experimental action runner for executing commands on remote Windows hosts.\r\n\r\nThe runner utilizes and offloads hard-work to `winexe` (http://sourceforge.net/projects/winexe/). In the background, winexe utilizes WMI.\r\n\r\nWith this runner you can also execute power shell scripts, but they already need to exit on the server. I believe it should also be possible to replicate `run-remote-script` behavior and copy script files to a remote host utilizing Samba protocol.\r\n\r\nThe \"hardest\" part is building winexe (if you want to use latest version from git) and configuring Windows server. Luckily most cloud providers already enable WMI by default on the cloud servers so only thing you need to do is to configure the firewall.\r\n\r\n(As you may see in the examples, I've tested on on Windows 2008 and Windows 2012 Rackspace cloud servers).\r\n\r\nNote: This is purely experimental, if we ever wanted to merge this, I would need to add better error handling, tests, documentation, etc.\r\n\r\n## Examples\r\n\r\n```bash\r\npython ./st2client/st2client/shell.py run core.windows host=x.y.z password=\"xxx\" cmd=\"ipconfig /all\"\r\n\r\nstatus: succeeded\r\nresult: \r\n{\r\n    \"stdout\": \"Windows IP Configuration\r\n\r\n   Host Name . . . . . . . . . . . . : TEST-WINDOWS-20\r\n   Primary Dns Suffix  . . . . . . . : \r\n   Node Type . . . . . . . . . . . . : Hybrid\r\n   IP Routing Enabled. . . . . . . . : No\r\n   WINS Proxy Enabled. . . . . . . . : No\r\n\r\nEthernet adapter private0:\r\n\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Citrix PV Ethernet Adapter #1\r\n   Physical Address. . . . . . . . . : BC-76-4E-10-0D-67\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n   IPv4 Address. . . . . . . . . . . : 10.209.96.125(Preferred) \r\n   Subnet Mask . . . . . . . . . . . : 255.255.224.0\r\n   Default Gateway . . . . . . . . . : \r\n   DHCPv6 IAID . . . . . . . . . . . : 331118158\r\n   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1C-A0-8A-25-BC-76-4E-10-09-3C\r\n   DNS Servers . . . . . . . . . . . : 173.203.4.9\r\n                                       173.203.4.8\r\n   NetBIOS over Tcpip. . . . . . . . : Enabled\r\n\r\nEthernet adapter public0:\r\n\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Citrix PV Ethernet Adapter #0\r\n   Physical Address. . . . . . . . . : BC-76-4E-10-09-3C\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n   IPv6 Address. . . . . . . . . . . : 2001:4801:7824:101:be76:4eff:fe10:93c(Preferred) \r\n   IPv4 Address. . . . . . . . . . . : 23.253.20.140(Preferred) \r\n   Subnet Mask . . . . . . . . . . . : 255.255.255.0\r\n   Default Gateway . . . . . . . . . : fe80::def%12\r\n                                       23.253.20.1\r\n   DHCPv6 IAID . . . . . . . . . . . : 264009294\r\n   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1C-A0-8A-25-BC-76-4E-10-09-3C\r\n   DNS Servers . . . . . . . . . . . : 173.203.4.9\r\n                                       173.203.4.8\r\n   NetBIOS over Tcpip. . . . . . . . : Enabled\r\n\r\nTunnel adapter Local Area Connection* 11:\r\n\r\n   Media State . . . . . . . . . . . : Media disconnected\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter\r\n   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n\r\nTunnel adapter isatap.{DA3F6EFD-C0F4-4338-B270-8BDB9E9FF0D9}:\r\n\r\n   Media State . . . . . . . . . . . : Media disconnected\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2\r\n   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\", \r\n    \"stderr\": \"\", \r\n    \"exit_code\": 0,\r\n    \"result\": \"Windows IP Configuration\r\n\r\n   Host Name . . . . . . . . . . . . : TEST-WINDOWS-20\r\n   Primary Dns Suffix  . . . . . . . : \r\n   Node Type . . . . . . . . . . . . : Hybrid\r\n   IP Routing Enabled. . . . . . . . : No\r\n   WINS Proxy Enabled. . . . . . . . : No\r\n\r\nEthernet adapter private0:\r\n\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Citrix PV Ethernet Adapter #1\r\n   Physical Address. . . . . . . . . : BC-76-4E-10-0D-67\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n   IPv4 Address. . . . . . . . . . . : 10.209.96.125(Preferred) \r\n   Subnet Mask . . . . . . . . . . . : 255.255.224.0\r\n   Default Gateway . . . . . . . . . : \r\n   DHCPv6 IAID . . . . . . . . . . . : 331118158\r\n   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1C-A0-8A-25-BC-76-4E-10-09-3C\r\n   DNS Servers . . . . . . . . . . . : 173.203.4.9\r\n                                       173.203.4.8\r\n   NetBIOS over Tcpip. . . . . . . . : Enabled\r\n\r\nEthernet adapter public0:\r\n\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Citrix PV Ethernet Adapter #0\r\n   Physical Address. . . . . . . . . : BC-76-4E-10-09-3C\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n   IPv6 Address. . . . . . . . . . . : 2001:4801:7824:101:be76:4eff:fe10:93c(Preferred) \r\n   IPv4 Address. . . . . . . . . . . : 23.253.20.140(Preferred) \r\n   Subnet Mask . . . . . . . . . . . : 255.255.255.0\r\n   Default Gateway . . . . . . . . . : fe80::def%12\r\n                                       23.253.20.1\r\n   DHCPv6 IAID . . . . . . . . . . . : 264009294\r\n   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1C-A0-8A-25-BC-76-4E-10-09-3C\r\n   DNS Servers . . . . . . . . . . . : 173.203.4.9\r\n                                       173.203.4.8\r\n   NetBIOS over Tcpip. . . . . . . . : Enabled\r\n\r\nTunnel adapter Local Area Connection* 11:\r\n\r\n   Media State . . . . . . . . . . . : Media disconnected\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter\r\n   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\r\n\r\nTunnel adapter isatap.{DA3F6EFD-C0F4-4338-B270-8BDB9E9FF0D9}:\r\n\r\n   Media State . . . . . . . . . . . : Media disconnected\r\n   Connection-specific DNS Suffix  . : \r\n   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2\r\n   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0\r\n   DHCP Enabled. . . . . . . . . . . : No\r\n   Autoconfiguration Enabled . . . . : Yes\"\r\n}\r\n```\r\n\r\n```bash\r\npython ./st2client/st2client/shell.py run core.windows host=x.y.z password=\"xxx\" cmd=\"powershell.exe Get-Process\"\r\n\r\nstatus: succeeded\r\nresult: \r\n{\r\n    \"stdout\": \"Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName          \r\n-------  ------    -----      ----- -----   ------     -- -----------          \r\n     34       5     1016       2772    22     0.02   2732 conhost              \r\n    548      12     2208       4324    44     3.48    388 csrss                \r\n    114       9     1796       4096    38     0.12    440 csrss                \r\n    125       8     1944       4880    45     0.31   2212 csrss                \r\n    100       8     2176       6348    34     0.02   1404 dllhost              \r\n    191      15     4608      11380    57     0.69   1752 dllhost              \r\n     70       7     1516       4624    53     0.02   2248 dwm                  \r\n    537      39    15936      34116   214     0.86   2528 explorer             \r\n      0       0        0         24     0               0 Idle                 \r\n    151      23     7368      14776    84     0.14   2808 LogonUI              \r\n    835      27     4940      12344    42     1.03    540 lsass                \r\n    236      10     3132       6292    30     0.05    548 lsm                  \r\n    308      30    47672      42136   604     0.97    176 mmc                  \r\n    149      17     3312       7916    60     0.05   1928 msdtc                \r\n    612      40    64752      10516   624     1.33   2532 Oobe                 \r\n    262      21    68384      63180   576     0.44   1320 powershell           \r\n    930      52    63320      61552   560     1.25   2284 Rackspace.Cloud.Se...\r\n    168      27    25284      20640   493     0.28   2352 Rackspace.Cloud.Se...\r\n     85       7     1432       4156    54     0.05   2424 rdpclip              \r\n    217      12     4152       7912    33     1.01    524 services             \r\n     33       1      444       1100     4     0.02    304 smss                 \r\n    286      20     7772      13644    92     0.51   1312 spoolsv              \r\n    171       9     5504      11668    44     2.96    616 sppsvc               \r\n    354      14     3648       9220    41     0.58    652 svchost              \r\n    268      16     5120       9124    34     0.87    724 svchost              \r\n    256      14     2936       8532    35     0.31    816 svchost              \r\n    325      15     8784      11524    44     0.76    840 svchost              \r\n    409      17     5264      12560    68     0.37    880 svchost              \r\n   1811    1348   619684     383920  1089   391.59    920 svchost              \r\n    494      18     6036      11028    40     1.78    948 svchost              \r\n    534      38    15152      18188   355     0.81    976 svchost              \r\n    308      32     9220      11848    50     0.30   1216 svchost              \r\n     47       4      932       2720    13     0.00   1356 svchost              \r\n     69       7     1564       4600    29     0.06   1828 svchost              \r\n    104      13     2196       5868    34     0.02   2468 svchost              \r\n    623       0      112        304     3    23.70      4 System               \r\n    118      10     2576       5796    53     0.02   2220 taskhost             \r\n     45       4      936       2732    18     0.00   2572 winexesvc            \r\n     76       9     1444       4404    24     0.05    420 wininit              \r\n     98       9     2076       5532    56     0.27    480 winlogon             \r\n     96       7     1624       4952    30     0.03   2980 winlogon             \r\n    217      15     7016      13252    51     0.66   1096 WmiPrvSE             \r\n    147      10     3716       8120    33     0.89   1904 WmiPrvSE             \r\n    160      28    19500      21032   508     0.67   1860 XenDpriv             \r\n    463      39    40076      49492   565     1.59   1448 XenGuestAgent \", \r\n    \"stderr\": \"\", \r\n    \"exit_code\": 0,\r\n    \"result\": \"Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName          \r\n-------  ------    -----      ----- -----   ------     -- -----------          \r\n     34       5     1016       2772    22     0.02   2732 conhost              \r\n    548      12     2208       4324    44     3.48    388 csrss                \r\n    114       9     1796       4096    38     0.12    440 csrss                \r\n    125       8     1944       4880    45     0.31   2212 csrss                \r\n    100       8     2176       6348    34     0.02   1404 dllhost              \r\n    191      15     4608      11380    57     0.69   1752 dllhost              \r\n     70       7     1516       4624    53     0.02   2248 dwm                  \r\n    537      39    15936      34116   214     0.86   2528 explorer             \r\n      0       0        0         24     0               0 Idle                 \r\n    151      23     7368      14776    84     0.14   2808 LogonUI              \r\n    835      27     4940      12344    42     1.03    540 lsass                \r\n    236      10     3132       6292    30     0.05    548 lsm                  \r\n    308      30    47672      42136   604     0.97    176 mmc                  \r\n    149      17     3312       7916    60     0.05   1928 msdtc                \r\n    612      40    64752      10516   624     1.33   2532 Oobe                 \r\n    262      21    68384      63180   576     0.44   1320 powershell           \r\n    930      52    63320      61552   560     1.25   2284 Rackspace.Cloud.Se...\r\n    168      27    25284      20640   493     0.28   2352 Rackspace.Cloud.Se...\r\n     85       7     1432       4156    54     0.05   2424 rdpclip              \r\n    217      12     4152       7912    33     1.01    524 services             \r\n     33       1      444       1100     4     0.02    304 smss                 \r\n    286      20     7772      13644    92     0.51   1312 spoolsv              \r\n    171       9     5504      11668    44     2.96    616 sppsvc               \r\n    354      14     3648       9220    41     0.58    652 svchost              \r\n    268      16     5120       9124    34     0.87    724 svchost              \r\n    256      14     2936       8532    35     0.31    816 svchost              \r\n    325      15     8784      11524    44     0.76    840 svchost              \r\n    409      17     5264      12560    68     0.37    880 svchost              \r\n   1811    1348   619684     383920  1089   391.59    920 svchost              \r\n    494      18     6036      11028    40     1.78    948 svchost              \r\n    534      38    15152      18188   355     0.81    976 svchost              \r\n    308      32     9220      11848    50     0.30   1216 svchost              \r\n     47       4      932       2720    13     0.00   1356 svchost              \r\n     69       7     1564       4600    29     0.06   1828 svchost              \r\n    104      13     2196       5868    34     0.02   2468 svchost              \r\n    623       0      112        304     3    23.70      4 System               \r\n    118      10     2576       5796    53     0.02   2220 taskhost             \r\n     45       4      936       2732    18     0.00   2572 winexesvc            \r\n     76       9     1444       4404    24     0.05    420 wininit              \r\n     98       9     2076       5532    56     0.27    480 winlogon             \r\n     96       7     1624       4952    30     0.03   2980 winlogon             \r\n    217      15     7016      13252    51     0.66   1096 WmiPrvSE             \r\n    147      10     3716       8120    33     0.89   1904 WmiPrvSE             \r\n    160      28    19500      21032   508     0.67   1860 XenDpriv             \r\n    463      39    40076      49492   565     1.59   1448 XenGuestAgent \"\r\n}\r\n```\r\n\r\n```bash\r\npython ./st2client/st2client/shell.py run core.windows host=x.y.z password=\"xxx\" cmd=\"powershell.exe Geet-Process\"\r\n\r\nstatus: failed\r\nresult: \r\n{\r\n    \"stdout\": \"\", \r\n    \"stderr\": \"Geet-Process : The term 'Geet-Process' is not recognized as the name of a \r\ncmdlet, function, script file, or operable program. Check the spelling of the \r\nname, or if a path was included, verify that the path is correct and try again.\r\nAt line:1 char:1\r\n+ Geet-Process\r\n+ ~~~~~~~~~~~~\r\n    + CategoryInfo          : ObjectNotFound: (Geet-Process:String) [], Comman \r\n   dNotFoundException\r\n    + FullyQualifiedErrorId : CommandNotFoundException\", \r\n    \"exit_code\": 1,\r\n    \"result\": \"\"\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/StackStorm/st2/issues/comments/84756590","html_url":"https://github.com/StackStorm/st2/pull/1287#issuecomment-84756590","issue_url":"https://api.github.com/repos/StackStorm/st2/issues/1287","id":84756590,"user":{"login":"dzimine","id":1294734,"avatar_url":"https://avatars.githubusercontent.com/u/1294734?v=3","gravatar_id":"","url":"https://api.github.com/users/dzimine","html_url":"https://github.com/dzimine","followers_url":"https://api.github.com/users/dzimine/followers","following_url":"https://api.github.com/users/dzimine/following{/other_user}","gists_url":"https://api.github.com/users/dzimine/gists{/gist_id}","starred_url":"https://api.github.com/users/dzimine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dzimine/subscriptions","organizations_url":"https://api.github.com/users/dzimine/orgs","repos_url":"https://api.github.com/users/dzimine/repos","events_url":"https://api.github.com/users/dzimine/events{/privacy}","received_events_url":"https://api.github.com/users/dzimine/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T02:22:07Z","updated_at":"2015-03-23T02:22:07Z","body":"nice!\r\n\r\ncurious to know about winexe path vs wmi path? "}}