Wednesday 29 May 2013

Task Sequence Fail on Computer Rebuild

The following instructions can be used when you are trying, and failing, to rebuild a machine by booting it from a cd/usb stick and then pushing a Task Sequence down from SCCM. In this case the machine is refusing to acknowledge the existence of said Task Sequence.

Although this very rarely solves any major issues you may be having, it can be worth a shot once you've exhausted all the usual routes.

If the machine is refusing to find the Task Sequence on the network and kicking back a Task Sequence Not Found/Located message, there's an outside chance it could be because some remnant of the old system is screwing things up. As such we need to wipe the hard drive of the machine.

At the point where the failure message pops up, do the following:
 
Press F8

Type Diskpart at the dos prompt 

Then type Select Disk 0

Then type Clean

Then type Exit
 
Once this is done you can restart. Congratulations, you now stand a slightly improved chance of the machine picking up the Task Sequence from SCCM.

Tuesday 28 May 2013

Batch File to Reboot Multiple Computers

Part 1 - the command line:


This is a pretty simple but can be quite handy. This is the basic command line:

shutdown -r -m \\Computer_Name -t 30 -c "This computer is shutting down in 30 seconds. Best log off now"

The above command, if entered into the cmd line utility, will:
shutdown (shutdown),
then restart (-r),
a specific machine (-m \\ComputerName), 
with a 30 second delay after the command is sent before shutdown command is initialised (-t 30),
And it will also display a comment to whoever happens to be logged on (-c "I am now sentient and have decided to switch myself off in 30 seconds"). 


 
Part 2 - creating the batch file:

Open notepad and then paste the above command line in as many times as needed, tweaking the computer name each time

shutdown -r -m \\ComputerNameA -t 30 -c "This computer is shutting down in 30 seconds. Best log off now"
shutdown -r -m \\ComputerNameB -t 30 -c "This computer is shutting down in 30 seconds. Best log off now"
shutdown -r -m \\ComputerNameC -t 30 -c "This computer is shutting down in 30 seconds. Best log off now"
shutdown -r -m \\ComputerNameD -t 30 -c "This computer is shutting down in 30 seconds. Best log off now"

Then if you Save As..., change the File Type to All Files and name it something useful like Multiple-reboot.bat, you'll have a shiny new batch file which can be run whenever you need or included as part of a scheduled task.

Monday 27 May 2013

Cleaning Up Active Directory

The following command line will trundle through Active Directory and pull out a list of any machine/computer accounts which have been inactive for more than 12 weeks:
 
Dsquery computer “OU=Example Standard Computers,OU=Desktops,OU=All Workstations,DC=web,DC=local” –inactive 12

 If you want the command to then disable the accounts you can pipe the dsmod command onto the end of the line:
 


Dsquery computer “OU=Example Standard Computers,OU=Desktops,OU=All Workstations,DC=web,DC=local” –inactive 12 | dsmod computer –disabled yes

 
If you inadvertently disabled too many accounts or need to undo what you've done, you can run the above command but change the end from dsmod computer –disabled yes to dsmod computer –disabled no.

Alternatively if you want the command to then delete the accounts you can change the end of the command to the following:

Dsquery computer “OU=Example Standard Computers,OU=Desktops,OU=All Workstations,DC=web,DC=local” –inactive 12 | dsrm -c -noprompt

NB: the Delete command should be used with caution. Since the last logon times (which inform the -inactive part of the query) are not replicated between Domain Controllers, it is always a good idea to first disable all the machine accounts, leave them for a few weeks and then delete them.

You can paste any of these commands into notepad and save it as a batch file (add the suffix .bat onto the filename when you Save As...). The batch file can then be used as part of a Scheduled Task to automate the process and keep Active Directory tidy. You can also run these commands as Powershell commands.