Skip to content

-Verb RunAs - no output #86

@akozyreva

Description

@akozyreva

Hello! I need to execute specific powershell command in Java as admin. It works fine, but doesn't return any output. This is my code:

static void runPowerShellScript(){
        try (PowerShell powerShell = PowerShell.openSession("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" )) {
            PowerShellResponse  response = powerShell.executeCommand("Start-Process  -FilePath \"powershell\" -Verb RunAs -ArgumentList 'dir'");
             System.out.println("Script output:" + response.getCommandOutput());
        } catch(PowerShellNotAvailableException ex) {
            System.out.println(ex);
        }
    }

Any ideas, how I can catch output from it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions