Unable to use invoke-command

Welcome Forums General PowerShell Q&A Unable to use invoke-command

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
4 months ago.

  • Author
    Posts
  • #102650

    Participant
    Points: 0
    Rank: Member

    Hi All,

    I need to install a software on multiple computers. The setup file is residing on one of the jump box. Below is the switch to install the software locally, I tried this below command locally on server and it works:

    \\\SCCMSources\Applications\CrowdStrike\CrowdStrike_3.1.5226.0\WindowsSensor.exe /install /quiet /norestart CID=000000000000000000000-00

    I want to use this command in invoke-command. I tried below command on localhost and on remote computer. It does not give any error message but does not do anything also.

    Invoke-Command -ScriptBlock {c:\temp\CrowdStrike_3.1.5226.0\WindowsSensor.exe /install /quiet /norestart CID=000000000000000000000-00} -ComputerName localhost

    It just do nothing, once I press enter, it goes to c:\>. Please help me running this command or let me know if you need any information my side.

  • #102655

    Participant
    Points: 15
    Rank: Member
    Get-Help -Name Invoke-Command -Examples
    
    NAME
        Invoke-Command
        
    SYNOPSIS
        Runs commands on local and remote computers.
        Example 1: Run a script on a server
        Invoke-Command -FilePath c:\scripts\test.ps1 -ComputerName Server01
      
        Example 2: Run a command on a remote server
        Invoke-Command -ComputerName server01 -Credential domain01\user01 -ScriptBlock {Get-Culture}
    …
    
  • #102683

    Participant
    Points: 4
    Rank: Member

    In some cases, when running commends on servers, I've to build up the command line, like this:

    $robocopyOptions = @('/E','/ZB','/J','/EFSRAW','/COPYALL','/XO','/R:3','/W:60','/NP','/xf','log*')
    $robocopyOptions += "/LOG:$($log)"
    $robocopyOptions += "/xf LOG* "
    
    $CmdLine = @($source, $destination) + $robocopyOptions
    & 'robocopy.exe' $CmdLine
    

    In some cases when running commands on remote servers I use a PSSession, like this:

    $pss = New-PSSession $Server -Credential (Import-Clixml "$codedeploy") 
    Invoke-Command -Session $pss -scriptblock { 
    yoursrcipt
    }
    

The topic ‘Unable to use invoke-command’ is closed to new replies.