Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to find out who on my network has Access installed. I have had several problems getting the list to work correctly, so I have used the output txt file. Anyway even if it's not a great way to do this it should still work. Can anyone tell me why this is not working?

$Computers = Get-QADComputer | select name | Out-File "c:\access_search.txt"
$Computers = Get-Content "c:\access_search.txt"
$Path = "\c$\Program Files\Microsoft Office\Office12\Access.pip"
$AccessPath = "\\" + $PCName + $Path
Foreach ($PCname in $Computers){
$Result = Test-Path $AccessPath
if ($Result -eq "True")
{$Pcname}
}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

You're not testing the correct path since it's being assigned prior to the foreach loop where you define $PCname. This means that you're testing the path \\\c$\Program Files\Microsoft Office\Office12\Access.pip every time.

Try this:

$Computers = Get-QADComputer | select name | Out-File "c:\access_search.txt"
$Computers = Get-Content "c:\access_search.txt"
$Path = "\c$\Program Files\Microsoft Office\Office12\Access.pip"
Foreach ($PCname in $Computers){
    $AccessPath = "\\" + $PCName + $Path
    $Result = Test-Path $AccessPath
    if ($Result -eq "True")
        {$Pcname}
}
share|improve this answer
    
This worked for my situation. I hate that i missed something so simple. Thank you –  Brandan Sep 21 '11 at 15:35
    
Bah, don't sweat it! If I had half a penny for every time I needed another pair of eyes.... –  squillman Sep 21 '11 at 15:49

While the approach of checking for a specific file might work in some cases, it doesn't account for either the file existing, but is not installed; or Access being installed but in a different location.

To avoid both of these WMI can be used (including remotely) to read the MSI data directly.

gwmi -comp ComputerNameGoesHere WIn32_SoftwareFeature -filter "name like 'access%' and productname like 'microsoft%'" |
  fl Name,ProductName,Version,Vendor

returned multiple results on each of two computers with Access (2010, one x86 once x64, as part of Office Professional Plus) and no results on a system without Office installed. Filter rules might need adjustments for a standalone Access install or earlier versions.

share|improve this answer
    
+1 This is a much better way of accomplishing this –  squillman Sep 21 '11 at 14:36
    
This does not return the computer name. This may not be the correct way to do this but if anyone is wanting to hack at this script I added a property that returns the pcname, and the search for access returned 12 results per computer with office plus, so i narrowed the search. $Result = gwmi -comp ComputerNameGoesHere WIn32_SoftwareFeature -filter "name like 'ACCESSFiles' and productname like 'microsoft%'" $Result | Add-Member -MemberType NoteProperty -Name PcName -Value $PCname $Result |format-List pcname, Productname, Version –  Brandan Sep 21 '11 at 18:46
    
@Brandan: First the computer name is the __SERVER property on the returned objects. Second computer name is an input parameter, to wrap this in a IsAccessInstalled function, it just needs a $true/$false return based on whether any objects are found. –  Richard Sep 22 '11 at 6:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.