Jump to content

Recommended Posts

Posted

Hi All

 

Hoping someone will know the answer to this as it will be a good win for us.

 

I have created a basic Powershell script to shutdown computers from a csv file. Any computer that is on it switches off and any computer that has someone logged into is left on. The issue i'm having is when it gets to a computer that is switched off already it takes 20 seconds before it moves onto the next computer.

 

The question is, is there a way to reduce the time it takes to move onto the next computer?

 

Thanks

ITTec

Posted

You can use the Test-Connection command to see if the computer is on which just sends a ping request

Test-Connection -BufferSize 32 -Count 1 -ComputerName 192.168.0.41 -Quiet

the -Quiet returns true or false

  • Thanks 1
Posted

Hi ITTec,

I have managed to shutdown pc form OU, check out script below. for each OU I created separate PS1 file and set to run on end of day.

each file get pc name from OU ping it if it get response then it will shut down pc and not give you any error.

still shorting out to see if user logged in it will prompt to cancel so they can keep continue to work.

Hope this will help.

 

Import-Module active*

 

$rtn = $null

 

Get-ADComputer -Filter * -SearchBase "OU=Room1,OU=Desktops,OU=Workstations,OU=Curriculum,DC=internal,DC=MySchool,DC=surrey,DC=sch,DC=uk" |

 

ForEach-Object {

 

$rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet

 

IF($rtn -match 'True') {Stop-Computer -ComputerName $_.dnshostname -Force}

 

}

Posted (edited)

Haven't tested it, but this should work, I'd excpect.

 

ForEach ($PC in (Get-ADComputer -SearchBase 'OU=Staff Computers,OU=Computers,DC=DOMAIN,DC=Local' -Filter 'ObjectClass -eq "Computer"')) {
   if (Test-Connection $PC -Count 1 -Quiet) {
       Stop-Computer -ComputerName $PC -Force
   }
}

 

If you want to apply this to multiple OU trees, just += them into an array ($AllPCs += (Get-ADComputer -Searchbase... etc)) and then use ForEach $PC in $AllPCs

Edited by Garacesh

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...