|
|
@ -57,79 +57,79 @@ If (-Not (Get-Command $executable -ErrorAction SilentlyContinue)) {
|
|
|
|
$module.FailJson("Executable '$executable' was not found.")
|
|
|
|
$module.FailJson("Executable '$executable' was not found.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$arguments = @()
|
|
|
|
$arguments = [System.Collections.Generic.List`1[String]]@($executable)
|
|
|
|
|
|
|
|
|
|
|
|
If ($nobanner -eq $true) {
|
|
|
|
If ($nobanner -eq $true) {
|
|
|
|
$arguments += "-nobanner"
|
|
|
|
$arguments.Add("-nobanner")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Support running on local system if no hostname is specified
|
|
|
|
# Support running on local system if no hostname is specified
|
|
|
|
If ($hostnames) {
|
|
|
|
If ($hostnames) {
|
|
|
|
$hostname_argument = ($hostnames | sort -Unique) -join ','
|
|
|
|
$hostname_argument = ($hostnames | sort -Unique) -join ','
|
|
|
|
$arguments += "\\$hostname_argument"
|
|
|
|
$arguments.Add("\\$hostname_argument")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Username is optional
|
|
|
|
# Username is optional
|
|
|
|
If ($username -ne $null) {
|
|
|
|
If ($null -ne $username) {
|
|
|
|
$arguments += "-u"
|
|
|
|
$arguments.Add("-u")
|
|
|
|
$arguments += $username
|
|
|
|
$arguments.Add($username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Password is optional
|
|
|
|
# Password is optional
|
|
|
|
If ($password -ne $null) {
|
|
|
|
If ($null -ne $password) {
|
|
|
|
$arguments += "-p"
|
|
|
|
$arguments.Add("-p")
|
|
|
|
$arguments += $password
|
|
|
|
$arguments.Add($password)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($chdir -ne $null) {
|
|
|
|
If ($null -ne $chdir) {
|
|
|
|
$arguments += "-w"
|
|
|
|
$arguments.Add("-w")
|
|
|
|
$arguments += $chdir
|
|
|
|
$arguments.Add($chdir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($wait -eq $false) {
|
|
|
|
If ($wait -eq $false) {
|
|
|
|
$arguments += "-d"
|
|
|
|
$arguments.Add("-d")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($noprofile -eq $true) {
|
|
|
|
If ($noprofile -eq $true) {
|
|
|
|
$arguments += "-e"
|
|
|
|
$arguments.Add("-e")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($elevated -eq $true) {
|
|
|
|
If ($elevated -eq $true) {
|
|
|
|
$arguments += "-h"
|
|
|
|
$arguments.Add("-h")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($system -eq $true) {
|
|
|
|
If ($system -eq $true) {
|
|
|
|
$arguments += "-s"
|
|
|
|
$arguments.Add("-s")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($interactive -eq $true) {
|
|
|
|
If ($interactive -eq $true) {
|
|
|
|
$arguments += "-i"
|
|
|
|
$arguments.Add("-i")
|
|
|
|
If ($session -ne $null) {
|
|
|
|
If ($null -ne $session) {
|
|
|
|
$arguments += $session
|
|
|
|
$arguments.Add($session)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($limited -eq $true) {
|
|
|
|
If ($limited -eq $true) {
|
|
|
|
$arguments += "-l"
|
|
|
|
$arguments.Add("-l")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($priority -ne $null) {
|
|
|
|
If ($null -ne $priority) {
|
|
|
|
$arguments += "-$priority"
|
|
|
|
$arguments.Add("-$priority")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($timeout -ne $null) {
|
|
|
|
If ($null -ne $timeout) {
|
|
|
|
$arguments += "-n"
|
|
|
|
$arguments.Add("-n")
|
|
|
|
$arguments += $timeout
|
|
|
|
$arguments.Add($timeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Add additional advanced options
|
|
|
|
# Add additional advanced options
|
|
|
|
If ($extra_opts) {
|
|
|
|
If ($extra_opts) {
|
|
|
|
ForEach ($opt in $extra_opts) {
|
|
|
|
ForEach ($opt in $extra_opts) {
|
|
|
|
$arguments += $opt
|
|
|
|
$arguments.Add($opt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$arguments += "-accepteula"
|
|
|
|
$arguments.Add("-accepteula")
|
|
|
|
|
|
|
|
|
|
|
|
$argument_string = Argv-ToString -arguments $arguments
|
|
|
|
$argument_string = Argv-ToString -arguments $arguments
|
|
|
|
|
|
|
|
|
|
|
@ -138,9 +138,9 @@ $argument_string = Argv-ToString -arguments $arguments
|
|
|
|
$argument_string += " $command"
|
|
|
|
$argument_string += " $command"
|
|
|
|
|
|
|
|
|
|
|
|
$start_datetime = [DateTime]::UtcNow
|
|
|
|
$start_datetime = [DateTime]::UtcNow
|
|
|
|
$module.Result.psexec_command = "$executable $argument_string"
|
|
|
|
$module.Result.psexec_command = $argument_string
|
|
|
|
|
|
|
|
|
|
|
|
$command_result = Run-Command -command "$executable $argument_string"
|
|
|
|
$command_result = Run-Command -command $argument_string
|
|
|
|
|
|
|
|
|
|
|
|
$end_datetime = [DateTime]::UtcNow
|
|
|
|
$end_datetime = [DateTime]::UtcNow
|
|
|
|
|
|
|
|
|
|
|
|