Solved

retrieve services from the remote computer

Posted on 2013-12-31
8
260 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
  • 4
  • 4
8 Comments
 
LVL 18

Assisted Solution

by:Jeremy Weisinger
Jeremy Weisinger earned 500 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 18

Assisted Solution

by:Jeremy Weisinger
Jeremy Weisinger earned 500 total points
ID: 39749082
Just tested it and it works for me. What errors are you getting?
0
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Accepted Solution

by:
Jeremy Weisinger earned 500 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 18

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now