Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

powershell to linux

Hi Experts,

I want to connect to multiple redhat machines from Windows powershell and retrieve configuration info from redhat systems.

What is the best way to achieve this. ?

I know there is a putty tool to connect to linux systems but is there a way to retrieve info from redhat machines like CPU, memory etc.

I would really appreciate if you could help..
Avatar of Brandon Mac
Brandon Mac

to install powershell on your systems that have redhat please see the following information
https://www.howtogeek.com/267858/how-to-install-microsoft-powershell-on-linux-or-os-x/ 

To get information using powershell from these systems see the following script
$pcs = get-content -path c:\listpc.txt
foreach($pc in $pcs){
$computerSystem = Get-CimInstance CIM_ComputerSystem
$computerBIOS = Get-CimInstance CIM_BIOSElement
$computerOS = Get-CimInstance CIM_OperatingSystem
$computerCPU = Get-CimInstance CIM_Processor
$computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
Clear-Host

Write-Host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
"HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerSystem.UserName
"Last Reboot: " + $computerOS.LastBootUpTime
}
alternative to powershell you can use built in tools to get this information from linux systems

http://www.computerworld.com/article/2825679/operating-systems/unix--automating-your-server-inventory.html
Avatar of DevSupport

ASKER

Hi Brandon
The above solution helps in getting values for Windows but I am not getting any output for linux environments:

On the linux powershell when I do:

PS /root> Get-CimInstance CIM_Processor

Get-CimInstance : The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.

If there is a way to execute commands from a Windows machine into a linux machine, and retrieve results that would be great
At line:1 char:1
+ Get-CimInstance CIM_Processor
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


I only get errors.
In the loop you need to add -ComputerName $pc to each Get-CimInstance, and run the complete script on a single (Windows) machine.
I tried but got the error about winrm service in the remote machine serv1.
As it is a linux machine on the remote host is it possible to have winrm there?

PS C:\Users\abc> Get-CimInstance -Computername serv1 CIM_ComputerSystem
Get-CimInstance : WinRM cannot process the request. The following error occurred while using Kerberos authentication:
Cannot find the computer serv1. Verify that the computer exists on the network and that the name provided is spelled
correctly.
At line:1 char:1
+ Get-CimInstance -Computername vapexdb CIM_ComputerSystem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
SOLUTION
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
Thank You so much for the help with these topics!
Sorry for the delay here in answering back, did you try the commands I gave you for Linux as well? Did you success fully install Linux this is very new to the IT world do I was curious to see the results as they recently just released PS to open source.