Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper function to execute Sysinternals PsExec #1266

Merged
merged 1 commit into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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