Solved

retrieve services from the remote computer

Posted on 2013-12-31
8
263 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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...
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

864 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

24 Experts available now in Live!

Get 1:1 Help Now