validate paths collecting from variable
Hi,

I have a Powershell script (paths.ps1) that has around 30 variables containing different paths. few variables are dependent on other variables to get part of the path and make the full path. Several other Powershell scripts actually use the script paths.ps1 to get the location of the different executable. What I want is to validate all paths under the variable and make sure all actually exist. I can use test-path command to validate the paths, but it's bit tricky to get the full paths from the variables. You can there are 3 level of dependency are available in the script. All I need to make sure is all paths are exist and print the full paths in a log with result.

----------------------------------
$AppServer = "\\FTS52009\"
$DbServer = "\\FTS53009\"
$FtpServer = "\\FTS72009\"

$automation = $AppServer + "automation\"
$loggen = $automation + "loggen.exe"
$FxTrading = $AppServer + "apps\fxtrading.exe"
$calc = $AppServer + "apps\calc.exe"
$surge = $DbServer + "process\data\surgeapp.exe"
$ftpincoming = $FtpServer + "incoming\"
$ftpoutgoing = $FtpServer + "outgoing\"
----------------------------------

I tried to read the content of the paths.ps1 by using Get-Content command and put all rows into an array. But how to deal with the dependency so one variable can get the path definitions from the variable it's dependent to?



  • Edited by cloudify 17 hours 9 minutes ago
August 25th, 2015 9:53am

Hi Cloudify,

if this Scriptfile has nothing but path definitions such as you posted here, you can do this by ...

  1. Read script to one combined multiline string
  2. User PowerShell parser to get the variable names
  3. dot-invoke the expression, to get the variables into the current scope
  4. Loop over the variable names and check their values.

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 9:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics