hi Luc ,
can you suggest if we can reslolve above error if the destination server has port 5986 open (for https communication)
right now only http(5985)is open .
Yes, that is another option, but not in the way you used it.
Like this, it should work
invoke-command -Session $sessions -ScriptBlock {
$cpu=Get-WmiObject -Class win32_processor
$avgcpu=($cpu.loadpercentage | Measure-Object -Average).average
"" | select @{N='Host';E={$env:COMPUTERNAME}},@{N = 'cpu percentage usage';E={$avgcpu}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not sure that will be enough.
Have a look at https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server for a more extensive procedure.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tx luc ,i m going to check this it seems this should fix .
i found this video which has almost everthing covered .thought of sharing .
i will check on some test servers if i find any...
That looks like a decent training series.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
if you can tell me how to get following from powershell .iam planning to use invoke-command and the script block to get following .
Why Invoke-Command?
You can also do
$cpu = Get-WmiObject -ComputerName $computerName -Class win32_processor -ErrorAction Stop
$mem = Get-WmiObject -ComputerName $computerName -Class win32_operatingsystem -ErrorAction Stop
[PSCustomObject]@{
Host = $computerName
CPU = $cpu.LoadPercentage
Mem = [math]::Round(($mem.TotalVisibleMemorySize -$mem.FreePhysicalMemory)/$mem.TotalVisibleMemorySize * 100)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this is to fetch information from remote systems .
so i want to put code in scriptblock and use invoke-command for multiple computers sessions
something like below .
$multisession=new-pssession -computername com1,com2,com3 -credential $cred
$multisesion will have session to multiple computers here com1,com2,com3
now we can use
invoke-command -session $multisession -scriptblock{code}
Then you just use the Get-WmiObject in the scriptblock, minus the CompterName.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
for the time being let me concentrate on cpu part . i think average part will give us the result which are comparable to the data given by most of the tools used to monitor the cpu usage .
is that correct??
$cpu = Get-WmiObject -ComputerName $computerName -Class win32_processor
Yes, the average would be the single value you see in the Task Manager
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$sessions=new-pssession -ComputerName com1,com2,com3
invoke-command -Session $sessions -ScriptBlock {
$cpu=Get-WmiObject -Class win32_processor
#$cpu.loadpercentage
$avgcpu=($cpu.loadpercentage | Measure-Object -Average).average
$env:COMPUTERNAME|select @{N = 'cpu percentage usage';E={$avgcpu}}
}
if yu can check the above for cpu (if yu have multiple windows machines) .
I would run it like this
Invoke-Command -Session $sessions -ScriptBlock {
[PSCustomObject]@{
CPU = ((Get-WmiObject -Class win32_processor).LoadPercentage |
Measure-Object -Average).average
}
} | Select PSComputerName,CPU
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
just thought of asking cant we run NE block inside script block.the one i posted ...
is there any thing which is fundamentally wrong??
Not sure what you mean?
What is a "NE block"?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry i mean
below kind of expression
$env:COMPUTERNAME|select @{N = 'cpu percentage usage';E={$avgcpu}}
Yes, that is another option, but not in the way you used it.
Like this, it should work
invoke-command -Session $sessions -ScriptBlock {
$cpu=Get-WmiObject -Class win32_processor
$avgcpu=($cpu.loadpercentage | Measure-Object -Average).average
"" | select @{N='Host';E={$env:COMPUTERNAME}},@{N = 'cpu percentage usage';E={$avgcpu}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
can you please tell me what is "" before pipeline .are we using it because there is no direct property (i.e computername and avgcpu)
""| select @{N='Host';E={$env:COMPUTERNAME}},@{N = 'cpu percentage usage';E={$avgcpu}}
You have to provide an input object (in this an empty string) to the Select-Object.
And then on the Select-Object you can use calculated properties (your NE block :smileygrin:)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks i will be adding memory also .