Not sure if I need to put this in a new topic or not. But in conjunction with task, i wanted to get a list of all servers and their current status of WinRM. I was able to come up with this:
$computername = get-content "C:\temp\st\ServerListRM.txt"
$Query="select * from win32_service where name='WinRM'"
$ResultList = @()
foreach ($computer in $computername)
{
write-host "Getting WinRM Service for " $computer
$TempResult = Get-WmiObject -Query $query -computer $computer
If ($TempResult -ne $null) {
$ResultList += $TempResult
}
}
$ResultList| out-file "c:\temp\st\WinRM.txt"
I get the right results but I was hoping the Computer Name would be part of the WinRM.txt:
ExitCode : 0
Name : WinRM
ProcessId : 348
StartMode : Auto
State : Running
Status : OK
ExitCode : 0
Name : WinRM
ProcessId : 348
StartMode : Auto
State : Running
Status : OK
I've tried a couple of things but nothing is working. I had added:
Get-WmiObject win32_computersystem | Select-Object -Property name
But I could not add it correctly.
Thoughts?
Jr. Admin
$computername = get-content "C:\temp\st\ServerListRM.txt"
$Query="select * from win32_service where name='WinRM'"
$ResultList = @()
foreach ($computer in $computername)
{
write-host "Getting WinRM Service for " $computer
$TempResult = Get-WmiObject -Query $query -computer $computer
If ($TempResult -ne $null) {
$ResultList += $TempResult
}
}
$ResultList| out-file "c:\temp\st\WinRM.txt"
I get the right results but I was hoping the Computer Name would be part of the WinRM.txt:
ExitCode : 0
Name : WinRM
ProcessId : 348
StartMode : Auto
State : Running
Status : OK
ExitCode : 0
Name : WinRM
ProcessId : 348
StartMode : Auto
State : Running
Status : OK
I've tried a couple of things but nothing is working. I had added:
Get-WmiObject win32_computersystem | Select-Object -Property name
But I could not add it correctly.
Thoughts?
Jr. Admin
Jr. Admin