Solved

Modify Service settings

Posted on 2011-02-15
6
915 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
  • 3
  • 3
6 Comments
 
LVL 70

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 70

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
Does Powershell have you tied up in knots?

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

 

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 70

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

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.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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