We help IT Professionals succeed at work.

Invoke command powershell

Suresh Kumar
Suresh Kumar asked
on
172 Views
Last Modified: 2017-03-21
Is there any command available  similar to invoke command  in powershell to run on remote machine?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Sysinternals psexec should do what you want:
https://technet.microsoft.com/en-us/sysinternals/bb897553
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
Yes, this will run Get-UICulture against Server01 and Server02
Invoke-Command -ComputerName Server01, Server02 {Get-UICulture}

Open in new window

or run a script
Invoke-Command -ComputerName Server01, Server02 -FilePath c:\Temp\SomeScript.ps1

Open in new window

Author

Commented:
[CmdletBinding()]
Param(
    [Parameter(Position=0,ValuefromPipeline=$true)]
    [string]$ComputerName = $env:ComputerName
)
$Head = @'
<style>
TABLE      {border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;}
TH            {border-width:1px; padding:2px; border-style:solid; border-color:black;}
TD            {border-width:1px; padding:2px; border-style:solid; border-color:black;}
</style>
'@

$Body = @'
<H2>Status for {0}</H2>
'@ -f $ComputerName

$Status = @()
$Stuff = @()
Invoke-Command -ComputerName $ComputerName -ScriptBlock {& opcagt -version} | ForEach-Object {
      
            $Stuff += $_
      
}
($Status | ConvertTo-Html -Head $Head -Body $Body -PostContent "<br /> $($Stuff -join '<br />')") -replace '^<html.*$', "<html>" | Out-file -Filepath C:\tmp\ver.txt
Get-Content 'C:\tmp\ver.txt' | Set-Content 'C:\tmp\ver1.txt'
cat C:\tmp\ver1.txt

This script works fine..but when i run the script through bladelogic tool .it is giving an error
is there any similar command  can i get for the below syntax without invoke or script block

Invoke-Command -ComputerName $ComputerName -ScriptBlock {& opcagt -version}
Simple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.