Link to home
Start Free TrialLog in
Avatar of Suresh Kumar
Suresh Kumar

asked on

Invoke command powershell

Is there any command available  similar to invoke command  in powershell to run on remote machine?
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Sysinternals psexec should do what you want:
https://technet.microsoft.com/en-us/sysinternals/bb897553
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

Avatar of Suresh Kumar
Suresh Kumar

ASKER

[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}
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial