\nThanks ich.ni.san and Neally. I’ll try these out later today or tomorrow. I got end users setting things on fire but you’ve given me two good ideas.<\/p>\n<\/blockquote>\n<\/aside>\n
Thanks. I would say I provided an idea, while Neally provided a “good” idea.<\/p>","upvoteCount":0,"datePublished":"2023-12-21T17:09:47.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/5","author":{"@type":"Person","name":"ich-ni-san","url":"https://community.spiceworks.com/u/ich-ni-san"}},{"@type":"Answer","text":"\n\n
<\/div>\n
ich.ni.san:<\/div>\n
\n\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\nThanks ich.ni.san and Neally. I’ll try these out later today or tomorrow. I got end users setting things on fire but you’ve given me two good ideas.<\/p>\n<\/blockquote>\n<\/aside>\n
Thanks. I would say I provided an idea, while Neally provided a “good” idea.<\/p>\n<\/blockquote>\n<\/aside>\n
Hey. It’s more than I had before, which was bupkiss. You also suggested the write-host computer which I was not aware of.<\/p>","upvoteCount":0,"datePublished":"2023-12-21T17:11:41.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/6","author":{"@type":"Person","name":"pcarter","url":"https://community.spiceworks.com/u/pcarter"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\nKeep in mind we should be using ‘cim’ really instead of WMI.<\/p>\n
$computers = Get-Content \"C:\\Temp2\\comp.csv\"\n\n$serviceReport = \nforeach ($computer in $computers){\n\n Get-CimInstance Win32_Service -ComputerName $computer | \n Where-Object {\n $_.startname -ne \"LocalSystem\" -and \n $_.startname -ne \"NT AUTHORITY\\LocalService\" -and \n $_.startname -ne \"NT AUTHORITY\\NetworkService\" -and\n $_.StartName -notlike \"\"\n } |\n foreach{\n [pscustomobject]@{\n ComputerName = $computer\n StartName = $_.StartName\n ServiceName = $_.name \n }\n }\n\n}\n\n$serviceReport |\nexport-csv \"serviceReport-$(get-date -f 'yyyyMMdd').csv\" -NoTypeInformation\n<\/code><\/pre>\nyou might want to add error handling and such (if the machine is not reachable, etc)<\/p>\n<\/blockquote>\n<\/aside>\n
Thanks man I think you got me pointed in the right direction. There’s a few odds and ends I’m trying to sort out with the .txt file and other such things but I appreciate your help.<\/p>","upvoteCount":0,"datePublished":"2023-12-27T15:21:25.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/7","author":{"@type":"Person","name":"pcarter","url":"https://community.spiceworks.com/u/pcarter"}},{"@type":"Answer","text":"
care to elaborate?<\/p>\n\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\nThere’s a few odds and ends I’m trying to sort out with the .txt file and other such things<\/p>\n<\/blockquote>\n<\/aside>","upvoteCount":0,"datePublished":"2023-12-27T15:24:30.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\ncare to elaborate?<\/p>\n\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\nThere’s a few odds and ends I’m trying to sort out with the .txt file and other such things<\/p>\n<\/blockquote>\n<\/aside>\n<\/blockquote>\n<\/aside>\n
I have a script that scans active directory and spits out a list of computers. When I reference this list, I get a bunch of errors saying powershell can’t connect to the specified destination and then lists the computer name. When I manually put the servers I want in there, it works.<\/p>\n
I mean, I’m after servers in particular but my sup wants to know what other services may or may not be running on whatever computer across the domain. I’m fairly green where it comes to Powershell (thus my inquiry) so maybe this is not possible? I don’t know.<\/p>","upvoteCount":0,"datePublished":"2023-12-27T16:04:48.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/9","author":{"@type":"Person","name":"pcarter","url":"https://community.spiceworks.com/u/pcarter"}},{"@type":"Answer","text":"\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\n\n\n
<\/div>\n
Neally:<\/div>\n
\ncare to elaborate?<\/p>\n\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\nThere’s a few odds and ends I’m trying to sort out with the .txt file and other such things<\/p>\n<\/blockquote>\n<\/aside>\n<\/blockquote>\n<\/aside>\n
I have a script that scans active directory and spits out a list of computers. When I reference this list, I get a bunch of errors saying powershell can’t connect to the specified destination and then lists the computer name. When I manually put the servers I want in there, it works.<\/p>\n
I mean, I’m after servers in particular but my sup wants to know what other services may or may not be running on whatever computer across the domain. I’m fairly green where it comes to Powershell (thus my inquiry) so maybe this is not possible? I don’t know.<\/p>\n<\/blockquote>\n<\/aside>\n
I’ll also add, I frequently use powershell to reference a list of computers and do $thing so I know PS remoting is enabled on our domain. Why it won’t work in this instance is beyond me.<\/p>","upvoteCount":0,"datePublished":"2023-12-27T16:14:06.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/10","author":{"@type":"Person","name":"pcarter","url":"https://community.spiceworks.com/u/pcarter"}},{"@type":"Answer","text":"\n\n
<\/div>\n
AnungUnRama:<\/div>\n
\nWhen I reference this list, I get a bunch of errors saying powershell can’t connect to the specified destination<\/p>\n<\/blockquote>\n<\/aside>\n
could be a bunch of reason. Depends on the specific error message.<\/p>\n
Maybe the account does not have the right rights, maybe it’s long latency and it times out, maybe WinRM is not setup all the way, maybe it’s an older OS and needs WMI rather than CIM , etc.<\/p>","upvoteCount":1,"datePublished":"2023-12-27T16:30:03.000Z","url":"https://community.spiceworks.com/t/list-logon-user-for-services/964283/11","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}}]}}
pcarter
(AnungUnRama)
December 21, 2023, 2:37pm
1
Okay I am almost there on this one but stuck with the last piece. I want to get a list of services on remote servers, and filter out things like “NT Authority” and such. K. I got that figured out. I can also do it one server at a time. What I want to do is run it against a .txt list using a “foreach” statement and there is where I get stuck. Either I get a dump of stuff that does me do good, or a bunch of errors depending on how I do this. I also need to know what server is running what service. Here’s what I’ve got, hopefully somebody can tell me either 1) this is not possible or 2) where I’m screwed up.
I’ve been trying this and looking stuff up for ages and I’m out of ideas.
$computers = bc "$path to text file containing servers)
foreach ($computer in $computers) {
Get-WMIObject Win32_Service -ComputerName $computer | Where-Object {$.startname -ne “localSystem” }| Where-Object {$ .startname -ne “NT AUTHORITY\LocalService” } |Where-Object {$_.startname -ne “NT AUTHORITY\NetworkService” } |select startname, name }
11 Spice ups
ich-ni-san
(ich.ni.san)
December 21, 2023, 3:12pm
2
Edit: Sorry, that wasn’t the answer.
Edit 2: This seems to work for me.
$computers = Get-Content -Path "C:\Temp2\comp.csv"
Foreach ($computer in $computers){
Get-WMIObject Win32_Service -ComputerName $computer | Where-Object {$_.startname -ne "LocalSystem" -and $_.startname -ne "NT AUTHORITY\LocalService" -and $_.startname -ne "NT AUTHORITY\NetworkService"} |select startname, name
}
Of course, “C:\Temp2\comp.csv” would need to be replaced with your path.
Edit 3: Adding “Write-Host $computer” as the first line of the foreach loop helps.
2 Spice ups
Neally
(Neally)
December 21, 2023, 4:26pm
3
Keep in mind we should be using ‘cim’ really instead of WMI.
$computers = Get-Content "C:\Temp2\comp.csv"
$serviceReport =
foreach ($computer in $computers){
Get-CimInstance Win32_Service -ComputerName $computer |
Where-Object {
$_.startname -ne "LocalSystem" -and
$_.startname -ne "NT AUTHORITY\LocalService" -and
$_.startname -ne "NT AUTHORITY\NetworkService" -and
$_.StartName -notlike ""
} |
foreach{
[pscustomobject]@{
ComputerName = $computer
StartName = $_.StartName
ServiceName = $_.name
}
}
}
$serviceReport |
export-csv "serviceReport-$(get-date -f 'yyyyMMdd').csv" -NoTypeInformation
you might want to add error handling and such (if the machine is not reachable, etc)
3 Spice ups
pcarter
(AnungUnRama)
December 21, 2023, 5:05pm
4
Thanks @ich-ni-san and @alexw . I’ll try these out later today or tomorrow. I got end users setting things on fire but you’ve given me two good ideas.
ich-ni-san
(ich.ni.san)
December 21, 2023, 5:09pm
5
Thanks. I would say I provided an idea, while Neally provided a “good” idea.
pcarter
(AnungUnRama)
December 21, 2023, 5:11pm
6
Hey. It’s more than I had before, which was bupkiss. You also suggested the write-host computer which I was not aware of.
pcarter
(AnungUnRama)
December 27, 2023, 3:21pm
7
Neally:
Keep in mind we should be using ‘cim’ really instead of WMI.
$computers = Get-Content "C:\Temp2\comp.csv"
$serviceReport =
foreach ($computer in $computers){
Get-CimInstance Win32_Service -ComputerName $computer |
Where-Object {
$_.startname -ne "LocalSystem" -and
$_.startname -ne "NT AUTHORITY\LocalService" -and
$_.startname -ne "NT AUTHORITY\NetworkService" -and
$_.StartName -notlike ""
} |
foreach{
[pscustomobject]@{
ComputerName = $computer
StartName = $_.StartName
ServiceName = $_.name
}
}
}
$serviceReport |
export-csv "serviceReport-$(get-date -f 'yyyyMMdd').csv" -NoTypeInformation
you might want to add error handling and such (if the machine is not reachable, etc)
Thanks man I think you got me pointed in the right direction. There’s a few odds and ends I’m trying to sort out with the .txt file and other such things but I appreciate your help.
Neally
(Neally)
December 27, 2023, 3:24pm
8
pcarter
(AnungUnRama)
December 27, 2023, 4:04pm
9
Neally:
care to elaborate?
I have a script that scans active directory and spits out a list of computers. When I reference this list, I get a bunch of errors saying powershell can’t connect to the specified destination and then lists the computer name. When I manually put the servers I want in there, it works.
I mean, I’m after servers in particular but my sup wants to know what other services may or may not be running on whatever computer across the domain. I’m fairly green where it comes to Powershell (thus my inquiry) so maybe this is not possible? I don’t know.
pcarter
(AnungUnRama)
December 27, 2023, 4:14pm
10
AnungUnRama:
Neally:
care to elaborate?
I have a script that scans active directory and spits out a list of computers. When I reference this list, I get a bunch of errors saying powershell can’t connect to the specified destination and then lists the computer name. When I manually put the servers I want in there, it works.
I mean, I’m after servers in particular but my sup wants to know what other services may or may not be running on whatever computer across the domain. I’m fairly green where it comes to Powershell (thus my inquiry) so maybe this is not possible? I don’t know.
I’ll also add, I frequently use powershell to reference a list of computers and do $thing so I know PS remoting is enabled on our domain. Why it won’t work in this instance is beyond me.
Neally
(Neally)
December 27, 2023, 4:30pm
11
could be a bunch of reason. Depends on the specific error message.
Maybe the account does not have the right rights, maybe it’s long latency and it times out, maybe WinRM is not setup all the way, maybe it’s an older OS and needs WMI rather than CIM , etc.
1 Spice up