Suresh Kumar
asked on
Invoke command powershell
Is there any command available similar to invoke command in powershell to run on remote machine?
Yes, this will run Get-UICulture against Server01 and Server02
Invoke-Command -ComputerName Server01, Server02 {Get-UICulture}
or run a scriptInvoke-Command -ComputerName Server01, Server02 -FilePath c:\Temp\SomeScript.ps1
ASKER
[CmdletBinding()]
Param(
[Parameter(Position=0,Valu efromPipel ine=$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}
Param(
[Parameter(Position=0,Valu
[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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://technet.microsoft.