Monthly Archive


Folder information on remote machines

A question in the forums wanted to get the date a folder was changed on their domain controllers. This is one way to do it

$folder = "Common Files"            
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() |             
select -ExpandProperty DomainControllers |             
foreach {            
 $dc = $_.Name            
 if (Test-Path -Path "\\$dc\c$\Program Files (x86)\$folder") {            
  $data =  Get-Item "\\$dc\c$\Program Files (x86)\$folder" | select Fullname, LastWriteTime            
 else {            
  $data =  Get-Item "\\$dc\c$\Program Files\$folder" | select Fullname, LastWriteTime            
 $data | Add-Member -MemberType NoteProperty -Name Server -Value $dc -PassThru            

In this case the folder would only be in the 32 bit program files folder so see if “program files (x86)” exists – if so its 64 bit machine & we want that folder. if not we revert to “program files”

Final act is to add the computer name as a parameter – that could also be done as a calculated field in select

Leave a Reply