locked
Run Powershell script with arguments on remote system RRS feed

  • Question

  • $SystemName = 'GGCWS555'
    $creds = New-Object System.Management.Automation.PSCredential ("GGC\AlienGuy", (ConvertTo-SecureString "JustASimplePWD" -AsPlainText -Force)) 
    $session = New-PSSession -CN $SystemName -Authentication Credssp -Credential $creds 
    invoke-command -Session $session -Command (C:\temp\Desktop\MBAM\Invoke-MbamClientDeployment.ps1 -RecoveryServiceEndpoint "http://myMbam/MBAMRecoveryAndHardwareService/CoreService.svc" -EncryptionMethod "AES256" -EncryptAndEscrowDataVolumes -IgnoreEscrowOwnerAuthFailure)

    Hi,

     I am trying to run the PS Script Invoke-MbamClientDeployment.ps1 with the Arguments specified on a remote system but received error "Invoke-Command : Cannot validate argument on parameter 'ScriptBlock'. The argument is null. Provide a valid value for the argument, and then try running the command again."

    I have also tried

    $SystemName = 'GGCWS555'
    $creds = New-Object System.Management.Automation.PSCredential ("GGC\AlienGuy", (ConvertTo-SecureString "JustASimplePWD" -AsPlainText -Force))
    $session = New-PSSession -CN $SystemName -Authentication Credssp -Credential $creds

    $Args = '-RecoveryServiceEndpoint "http://myMBAM//MBAMRecoveryAndHardwareService/CoreService.svc" -EncryptionMethod "AES256" -EncryptAndEscrowDataVolumes -IgnoreEscrowOwnerAuthFailure' Invoke-Command -Session $session -ScriptBlock (C:\temp\Invoke-MbamClientDeployment.ps1) -ArgumentList $Args


     


    Monday, November 13, 2017 11:26 PM

Answers

  • You cannot hop over a system.

    You can do this:

    $argList = '-RecoveryServiceEndpoint http://myMbam/MBAMRecoveryAndHardwareService/CoreService.svc -EncryptionMethod AES256 -EncryptAndEscrowDataVolumes -IgnoreEscrowOwnerAuthFailure'
    invoke-command -Session $session -File C:\temp\Desktop\MBAM\Invoke-MbamClientDeployment.ps1 -ArgumentsList $rgList
    


    \_(ツ)_/

    Tuesday, November 14, 2017 4:01 AM

All replies

  • The PS1 file has to be on the remote server at that path.


    \_(ツ)_/

    Monday, November 13, 2017 11:39 PM
  • That makes sense. However, if my Invoke-MBAM.PS1 is located on a shared drive and I would like to run it with -Credential, how would I go about it?

    C:\temp\Desktop\MBAM\Invoke-MbamClientDeployment

    is now located

    \\server1\scritps\MBAM\Invoke-MbamClientDeployment

    1. If I replaced with \\server1\scritps\MBAM\Invoke-MbamClientDeployment , I will get Access Denied.

    Access is denied

        + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException

        + FullyQualifiedErrorId : System.UnauthorizedAccessException

    Tuesday, November 14, 2017 3:56 AM
  • You cannot hop over a system.

    You can do this:

    $argList = '-RecoveryServiceEndpoint http://myMbam/MBAMRecoveryAndHardwareService/CoreService.svc -EncryptionMethod AES256 -EncryptAndEscrowDataVolumes -IgnoreEscrowOwnerAuthFailure'
    invoke-command -Session $session -File C:\temp\Desktop\MBAM\Invoke-MbamClientDeployment.ps1 -ArgumentsList $rgList
    


    \_(ツ)_/

    Tuesday, November 14, 2017 4:01 AM
  • Hi,

    I am not gonna reply to your query, But would like to make a suggestion. Never write the password directly in the code. Instead use read-host


    (66,65,83,65,84,73|%{[char]$_})-join''

    Tuesday, November 14, 2017 4:46 AM
  • You are correct, I have another script that encrypt password and read from $cred.
    Tuesday, November 14, 2017 6:24 PM