Solved

Modify Service settings

Posted on 2011-02-15
6
921 Views
Last Modified: 2012-05-11
Hello,

I have the following script


$Computers = gc "c:\Active_Computers.txt"

$colItems = get-wmiobject -class "Win32_Service" -namespace "root\CIMV2" `
-computername $Computers

foreach ($objItem in $colItems) {

Write-Host  $Computers
write-host "Desktop Interact: " $objItem.DesktopInteract
Write-Host "Service Name :" $objItem.DisplayName

write-host
}


I would like to only tell me where the service named "Intel Local Scheduler Service" is set to   DesktopInteract = true and if it is change it to false

0
Comment
Question by:jfgray
[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
  • 3
  • 3
6 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34899664

Filter the results first:
Get-WmiObject Win32_Service -Filter "DisplayName='Intel Local Scheduler Service' AND DesktopInteract=$True"

Open in new window

Make sure that returns what you need first please :)

Then, if it does:
$Service = Get-WmiObject Win32_Service -Filter "DisplayName='Intel Local Scheduler Service' AND DesktopInteract=$True"
$Service.DesktopInteract = $False
$Service.Put()

Open in new window

And if all that works, reinstate the loop:
Get-Content C:\Active_Computers.txt | ForEach-Object {
  $Service = Get-WmiObject Win32_Service -ComputerName $_ `
    -Filter "DisplayName='Intel Local Scheduler Service' AND DesktopInteract=$True"
  If ($Service) {
    $Service.DesktopInteract = $False
    $Service.Put()
  }
}

Open in new window

HTH

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34899802

We might find that that option doesn't actually work. If you find that to be the case, pop back and we can call the Change method to modify it. It might just take a little experimentation to get there :)

Chris
0
 

Author Comment

by:jfgray
ID: 34900026
I can now filter for only that service and where objItem.DesktopInteract = True but it does not take the check mark out of "Allow service to interact with desktop"
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:jfgray
ID: 34900036
This is what I have so far

=====================================
$Computers = gc "c:\Active_Computers.txt"

$colItems = get-wmiobject -class "Win32_Service" -namespace "root\CIMV2" `
-computername $Computers -Filter "DisplayName='Intel Local Scheduler Service' AND DesktopInteract=$True"

foreach ($objItem in $colItems ) {

Write-Host  $objItem.SystemName
}
=====================================

0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 34900187
In that case we'll have to use the Change method.

Can we try...
Get-Content C:\Active_Computers.txt | ForEach-Object {
  $Service = Get-WmiObject Win32_Service -ComputerName $_ `
    -Filter "DisplayName='Intel Local Scheduler Service' AND DesktopInteract=$True"
  If ($Service) {
    $Service.Change($Null, $Null, $Null, $Null, $Null, $False, $Null, $Null, $Null, $Null, $Null)
  }
}

Open in new window

We may have to feed it the other values instead of Null, please use this on something we can safely test against, I'd hate to break something important.

Chris
0
 

Author Comment

by:jfgray
ID: 34900390
You the MAN !
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

739 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