Share via

remote access question

PowerShelly 61 Reputation points
2021-07-23T17:50:56.477+00:00

I'm trying to run ps1 file on remote server without logging on server.
example. local userinput.ps1 to run remote script.ps1 -userinput1 -userinput2 -userinput3 etc.

if i use:
$Credential = $host.ui.PromptForCredential("","","server")

would i still need this in my script?
New-PSSession -Session $s -Credential Domain01\User01

Once i have all the user inputs(GUI)
i want to have the OK button to execute remote script.ps1 -userinput1 -userinput2 -userinput3 etc.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2021-07-23T19:29:24.663+00:00

The first option takes FOUR parameters, not three! system.management.automation.host.pshostuserinterface.promptforcredential

For your intended purpose they both produce a usable result. Using the Get-Credential cmdlet offers less opportunity to make errors.

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. PowerShelly 61 Reputation points
    2021-07-26T13:43:17.547+00:00

    So your answer is YES, i need NEW-PSSession with $credential varible.
    So you recommend Get-credential cmdlet? is it GUI base? I will look into that.
    Man, there's so many way of doing things.

    Was this answer helpful?


  2. PowerShelly 61 Reputation points
    2021-07-23T19:06:25.813+00:00

    or maybe i should ask what's the difference between these 2?

    $Credential = $host.ui.PromptForCredential("","","server")

    New-PSSession -Session $s -Credential

    Was this answer helpful?

    0 comments No comments

  3. PowerShelly 61 Reputation points
    2021-07-23T19:02:18.183+00:00

    I already have the message box input generated, collect them all already.

    My question is before I run the script from local or remote,
    i'm using this for credential:

    $Credential = $host.ui.PromptForCredential("","","server")

    am i required to use this?
    New-PSSession -Session $s -Credential

    or they are just the same?

    hope that make sense.

    Was this answer helpful?


  4. Rich Matheisen 48,116 Reputation points
    2021-07-23T18:34:10.077+00:00
    1. Your 1st example has too few parameters. You need four, not three, in the PromptForCredential argument list.
    2. Your New-Session would replace the "Domain01/User01" with the $Credential variable.

    Assuming you mean a MessageBox, something like this would probably work:

    Add-Type -AssemblyName PresentationCore, PresentationFramework
        $msgBoxInput = [System.Windows.MessageBox]::Show('Run scripts?', 'Your input', 'YesNoCancel', 'Error')
        Switch ($msgBoxInput) {
            'Yes' {
                ## run scripts
            }
            'No' {
                Return
            }
            'Cancel' {
                Exit
            }
        }
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.