Skip to content

Commit

Permalink
Add helper function to execute Sysinternals PsExec
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazark committed Jun 13, 2016
1 parent 60acb2f commit 769c5d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="ServiceControllerHelper.fs" />
<Compile Include="GuardedAwaitObservable.fs" />
<Compile Include="ProcessHelper.fs" />
<Compile Include="PsExecHelper.fs" />
<Compile Include="NpmHelper.fs" />
<Compile Include="AppVeyor.fs" />
<Compile Include="BitbucketPipelines.fs" />
Expand Down
23 changes: 23 additions & 0 deletions src/app/FakeLib/PsExecHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Contains functions for working with Sysinternals PsExec
module Fake.PsExecHelper

let private formatArgs host username password exe inputs =
sprintf @"\\%s -u %s -p %s ""%s"" %s" host username password exe inputs

/// Use Sysinternals PsExec to execute a process on a remote machine.
/// ## Parameters
///
/// - `host` - The hostname of the machine to connect to.
/// - `username` - A username valid for connecting to the remote machine.
/// - `password` - The cleartext password of the given user.
/// - `exe` - The path to the file that is to be executed.
/// - `inputs` - The command-line arguments to pass to the remote process.
/// - `timeOut` - The timeout for PsExec.
let execRemote host username password exe inputs timeout =
let args = formatArgs host username password exe inputs
let exitCode =
ExecProcess (fun info ->
info.FileName <- "PsExec.exe"
info.Arguments <- args) timeout
if exitCode <> 0
then failwithf "Failed to execute %s as user %s on host %s with args %s" exe username host inputs

0 comments on commit 769c5d9

Please sign in to comment.