> I'm rather clueless with powershell. I'm now stuck at, how can I
> execute this powershell script block[2] in the same manner as ansible is
> doing it, to see why it's failing to install? Currently I take the
> scriptblock[2] as is and paste it in powershell which simply returns
> nothing to the screen.
OK, I think I run the powershell script like so via cmd:
powershell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted
Invoke-Command -ScriptBlock { param ( [String] $Arguments, [Int32[]]
$ReturnCodes, [Object] $Module, [String] $Path, [String] $State,
[String] $WorkingDirectory, [String] $RegistryPath, [Switch]
$WaitChildren ) $invokeParams = @{ Module = $Module ReturnCodes =
$ReturnCodes WorkingDirectory = $WorkingDirectory WaitChildren =
$WaitChildren } if ($Path) { $invokeParams.CommandLine =
ConvertTo-EscapedArgument -InputObject $Path } else { $registryProperties =
Get-ItemProperty -LiteralPath $RegistryPath if ('QuietUninstallString' -in
$registryProperties.PSObject.Properties.Name) { $command =
$registryProperties.QuietUninstallString } elseif ('UninstallString' -in
$registryProperties.PSObject.Properties.Name) { $command =
$registryProperties.UninstallString } else { $module.FailJson("Failed to
find registry uninstall string at registry path '$RegistryPath'") } # If the
uninstall string starts with '%', we need to expand the env vars. if
($command.StartsWith('%') -or $command.StartsWith('"%')) { $command =
[System.Environment]::ExpandEnvironmentVariables($command) } # If the
command is not quoted and contains spaces we need to see if it needs to be
manually quoted for the executable. if (-not $command.StartsWith('"') -and
$command.Contains(' ')) { $rawArguments =
[System.Collections.Generic.List[String]]@() $executable = New-Object
-TypeName System.Text.StringBuilder foreach ($cmd in ($command |
ConvertFrom-EscapedArgument)) { if ($rawArguments.Count -eq 0) { # Still
haven't found the path, append the arg to the executable path and see if it
exists. $null = $executable.Append($cmd) $exe = $executable.ToString() if
(Test-Path -LiteralPath $exe -PathType Leaf) { $rawArguments.Add($exe) }
else { $null = $executable.Append(" ") # The arg had a space and we need to
preserve that. } } else { $rawArguments.Add($cmd) } } # If we still
couldn't find a file just use the command literally and hope WIndows can handle
it, # otherwise recombine the args which will also quote whatever is needed.
if ($rawArguments.Count -gt 0) { $command = @($rawArguments |
ConvertTo-EscapedArgument) -join ' ' } } $invokeParams.CommandLine =
$command } if ($Arguments) { $invokeParams.CommandLine += " $Arguments" }
Invoke-Executable @invokeParams }
That results in this error:
'ConvertFrom-EscapedArgument))' is not recognized as an internal or external
command, operable program or batch file.
Anyone have a clue what's wrong?
My Powershell version is:
Name Value
---- -----
PSVersion 5.1.17763.5328
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5328
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
.net version is:
Release in one case says =0x00080eb1=
InstallPath =C:\Windows\Microsoft.Net\Framework64\v4.0.30319=
Version =4.8.03761=
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/87bk9n9d75.fsf%40swift.santanas.co.za.