26 October 2012

Find Old Computers in AD

For Windows 2003/2008
(Must be 2003 Native domain or newer)
In a Command Prompt window type:
dsquery computer -inactive <num>
Where <num> is the minimum number of weeks the device has been inactive for. Advice seems to be to use at least 2, as anything less than that is not fully reliable.

For Windows 2008 R2+
In a PowerShell  window type:
$time=Read-host "Enter a date in format mm/dd/yyyy"
then
Get-ADComputer -Filter * | Get-ADObject -Properties lastlogontimestamp | where {(([DateTime]::FromFileTime($_.lastlogontimestamp) - ([system.datetime]$time)).totaldays) -lt 0 } | select name

You can change what you include in the select command at the end to get more or different info.

If you want to then remove all resulting computer accounts use the following command:
Remove-ADObject -recursive
in place of the select name

That is, to remove all computers older than $time use the following command:
Get-ADComputer -Filter * | Get-ADObject -Properties lastlogontimestamp | where {(([DateTime]::FromFileTime($_.lastlogontimestamp) - ([system.datetime]$time)).totaldays) -lt 0 } | Remove-ADObject -recursive
For more detail or a better example (of which this is basically a cut and paste at the moment), see reference site below.

References:
http://blog.mattvogt.net/powershell-last-logon-timestamp-for-single-ho 

10 October 2012

Reset Offline Files Cache in Windows 7

To reset the offline files cache in Windows 7

  1. Create a registry file called resetcache.reg file with the following contents:

    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\CSC\Parameters] "FormatDatabase"=dword:00000001
  2. Double click the file and it should merge with registry. Alternatively, use command line:
    E.g. regedit.exe /s resetcache.reg
  3. Reboot the PC

Reference:
http://www.networknet.nl/apps/wp/archives/1093

Find the Desktop

It can be REALLY hard to access the desktop using scripts, especially batch scripts, if it has been moved from the default location of C:\Users\%username%, or even worse if it has been moved out of the %userprofile% location by the way of Folder Redirection.

As batch files cannot find this location, and I do not want to start learning VB script, I want a Powershell method I can use to find it.

This is the method I found:

$desktop = [Environment]::GetFolderPath("Desktop")

The $desktop variable now contains the location to the currently logged-in user's desktop. To view this path simply type

write-host $desktop

Happy day!

Reference:
The comment on the post at http://stackoverflow.com/questions/11349885/get-currently-logged-in-users-with-powershell-to-add-shortcut-to-desktop

:-)

17 September 2012

Windows Update 800B0001 Error

If Windows 7 clients are getting the following Windows Update error:
Windows could not search for new updates
An error occurred while checking for new updates for your computer.
Error(s) found:
Code 800B0001 Windows Update  encountered an unknown error.
 
Clients can still get updates from Microsoft Update, but anything from our WSUS does not work.
As it turns out Microsoft had updated the Windows Update client on Windows 7 and that an update (the number is KB2720211) was required on the WSUS server to allow the clients to continue to update.
Simple solution is to approve this update in WSUS and apply it to your servers, a bit of a pain is that this update requires a reboot of the server but hey its that or no updates for your clients!
 Thanks MyWorldOfIT

References:

13 September 2012

Force Windows to Check for Updates

To force Windows to check for updates type wuauclt /detectnow at a command prompt

05 September 2012

Black Screen When Restoring Minimised RDP Session

When restoring a minimised RDP session, often it will come up with a completely black screen, which won't go away for up to 20 seconds...not productivity friendly!

Try this on the client PC (not the remote server/PC):
  • In registry go to HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\
  • Create a new DWORD value named RemoteDesktop_SuppressWhenMinimized
  • Specify 2 as the value data.

Reference:
http://serverfault.com/questions/48650/remote-desktop-session-black-after-minimize

14 May 2012

Use proxy.pac to Auto Configure Proxy Settings

Proxy.pac files are great. They'll configure your proxy settings when you're on the protected network, but leave your system unaffected if you take it offsite to a network that does not require or use a proxy server.

Before I even begin to create something of my own I must recognise the following sources:
http://marckean.wordpress.com/2010/02/09/setting-up-proxy-pac-files-in-iis7-for-proxy-use/
http://nscsysop.hypermart.net/setproxy.html
http://nscsysop.hypermart.net/proxypac.html
http://technet.microsoft.com/en-us/library/dd361950.aspx

These sources are all you really need to get going, but I may put some more info up here more specific to the things I do with proxy.pac files.