0

I have two objects in my Powershell script - Application + Computer Objects which are imported from a csv file

# import applications

$apps = @()
$apps = Import-CSV C:\Working\fcheck_v2\apps.csv 

# import computer objects

$compobj = @()
$compobj = Import-CSV C:\Working\fcheck_v2\compobj.csv

The structure of apps.csv is as follows:

appname          location      lob
Core             C$\errlog.ini  RESEARCH    
Blmbg            C$\errlog.ini  RESEARCH    
Blmbg2           C$\errlog.ini  RESEARCH        
MLFR             C$\errlog.ini  LEGAL

The structure of compobj.csv is as follows:

hostname        lob
192.169.226.2   RESEARCH
192.169.226.5   HR

How would I use testpath to check whether a particular application exists on a computer?

For example I would want to test that all the computer objects in the RESEARCH lob have the RESEARCH apps installed on the machines and print out the results in a table like this:

hostname        lob           core     blmbg     blmbg2     mlfr
192.169.226.2   RESEARCH      True     True      False      Frue
192.169.226.5   HR            True      N/A       N/A       N/A

If the machine passes Test-Path - then the status is set to True

If the machine fails Test-Path+ app needs to be installed (i.e. it is in the lob) - then the status is set to False

If the machine fails Test-Path + app doesn't need to be installed (i.e. it is not in the lob) - then the status is set to N/A

Thanks.

2
  • I assume that you mean Test-Path Commented Oct 27, 2013 at 19:04
  • Yup - I've updated it Commented Oct 27, 2013 at 19:10

1 Answer 1

1

Here is some rough pseudo-code that will get you most of the way to what you're asking for. It should at least point you in the right direction. Re-reading your question, it may make more sense to re-order the loops and there is certainly some scope for optimization.

# foreach computer in compobj.csv
foreach $computer in $compobj
{
  # get the computers lob
  $computerLob = $computer.lob

  $lobApps = $apps | ? { $_.lob -eq $computerLob }

  foreach $app in $lobApps
  {
    # you will need to deal with authentication here 
    $result = Invoke-Command -ComputerName $computer.hostname -Script { if (Test-Path $app.location) { return "True" } else { return "False" } }

    # Write out suitable output... 
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Can you please give mean example of what you mean by suitable optimisaiton?
Well for one, I determine each loop what the LOB apps are - this can easily be determined once upfront. Overall though, I'd focus on getting it working first and then look to optimize.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.