ITTec Posted March 20, 2015 Posted March 20, 2015 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
Boredguy Posted March 20, 2015 Posted March 20, 2015 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 1
pcstru Posted March 20, 2015 Posted March 20, 2015 You could use start-job to run them in parallel. There is also a fast-ping thing kicking around or set a short timeout in test-connection. 1
ITTec Posted March 23, 2015 Author Posted March 23, 2015 Thanks both. Got that working with only a 5 second delay.
GAS Posted March 23, 2015 Posted March 23, 2015 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} }
Garacesh Posted March 23, 2015 Posted March 23, 2015 (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 March 23, 2015 by Garacesh
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now