Solved

Modify Service settings

Posted on 2011-02-15
6
907 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

21 Experts available now in Live!

Get 1:1 Help Now