Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

retrieve services from the remote computer

Posted on 2013-12-31
8
Medium Priority
?
278 Views
Last Modified: 2014-01-08
I have the script below that retrieves services from a local computer. I need an Expert to tweak this script so that I can retrieve services from remote computer.

I am not sure if using Psexec will be able to achieve the same goal

Thank you




$style = @"
  <style>
    TABLE {border-collapse: collapse}
    TD {border-width: 1px;padding: 5px;border-style: dotted;border-color: black}
  </style>
"@

Get-WmiObject win32_service |
  % {
    Add-Member -PassThru -InputObject $_ NoteProperty Delayed $(
      if ((Get-ItemProperty "HKLM:System\CurrentControlSet\Services\$($_.Name)").DelayedAutoStart -eq 1) { "x" }
    )
  } |
  select-object DisplayName, State, Startmode, Delayed |
  sort startmode, DisplayName |
  ConvertTo-HTML  -PreContent "<h1>$env:ComputerName</h1>$style" |
  % { $_ -Replace '<th>', '<td><strong>' -Replace '</th>', '</strong></td>'  } |
  Out-File C:\Test.html
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 21

Assisted Solution

by:Jeremy Weisinger
Jeremy Weisinger earned 2000 total points
ID: 39748664
Add the -ComputerName parameter to the Get-WMIObject.

$style = @"
  <style>
    TABLE {border-collapse: collapse}
    TD {border-width: 1px;padding: 5px;border-style: dotted;border-color: black}
  </style>
"@

Get-WmiObject win32_service -ComputerName nameofcomputer|
  % {
    Add-Member -PassThru -InputObject $_ NoteProperty Delayed $(
      if ((Get-ItemProperty "HKLM:System\CurrentControlSet\Services\$($_.Name)").DelayedAutoStart -eq 1) { "x" }
    )
  } | 
  select-object DisplayName, State, Startmode, Delayed |
  sort startmode, DisplayName |
  ConvertTo-HTML  -PreContent "<h1>$env:ComputerName</h1>$style" |
  % { $_ -Replace '<th>', '<td><strong>' -Replace '</th>', '</strong></td>'  } |
  Out-File C:\Test.html 

Open in new window

0
 

Author Comment

by:jskfan
ID: 39748908
That 's what I thought too...the scrip will throw errors....
have you tried it ?
0
 
LVL 21

Assisted Solution

by:Jeremy Weisinger
Jeremy Weisinger earned 2000 total points
ID: 39749082
Just tested it and it works for me. What errors are you getting?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:jskfan
ID: 39749101
one of the errors:

Get-ItemProperty : Cannot find path 'HKLM:\System\CurrentControlSet\Services\FCRegSvc' because it does not exist.
0
 

Author Comment

by:jskfan
ID: 39749102
it works when you run it against local computer only
0
 
LVL 21

Accepted Solution

by:
Jeremy Weisinger earned 2000 total points
ID: 39749133
You're right. I didn't see the Get-ItemProperty command in there.

The easiest way would be to go back to the original script and use the Invoke-Command. Save the script and then run:
Invoke-Command -ComputerName server1 -FilePath C:\servicesscript.ps1

Open in new window

If you have a list of computers you want to run it against then you can easily do that by running:
Foreach($srv in (get-content C:\computers.txt)){
    Invoke-Command -ComputerName $srv -FilePath C:\servicesscript.ps1
}

Open in new window

Also, I would change the output path to a centralized location and append the computer name to the file name.

More info on the Invoke-Command and remoting:
http://technet.microsoft.com/library/hh849719.aspx
http://technet.microsoft.com/en-US/library/hh847900.aspx
0
 

Author Closing Comment

by:jskfan
ID: 39766433
Thanks
0
 
LVL 21

Expert Comment

by:Jeremy Weisinger
ID: 39767014
Glad to help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question