user1717236
user1717236

Reputation: 11

Powershell Test-Path Not returning correct result

Hello if i run the following command I get a response of TRUE which is correct

Test-Path -Path "\\LT609247\c$\Users\*\AppData\Local\Microsoft\Outlook\*Internet Calendar*.pst"

However when I run the following commad in a script I get two FALSE returns. The iCalendar_Audit.csv contains two workstations one of which is LT609247.

$Computers = Get-Content c:\temp\iCalendar_Audit.csv

ForEach ($Computer in $Computers)

    { $ADComputer = $null

    $ADComputer = Get-ADComputer $Computer

    If ($ADComputer)

        { 

        Add-Content c:\temp\iCalendar_Audit.log -Value "Found $Computer, checking for iCalendar"

        Test-Path -Path "\\$ADComputer\c$\Users\*\AppData\Local\Microsoft\Outlook\*Internet Calendar*.pst"

        }
    } 

Upvotes: 0

Views: 171

Answers (1)

Vikas Gupta
Vikas Gupta

Reputation: 4465

$ADComputer will be an object, with several properties.. not a string with computer name. Assuming that $Computer is the computer name, you could either use $Computer like so -

Test-Path -Path "\\$Computer\c$\Users\*\AppData\Local\Microsoft\Outlook\*Internet Calendar*.pst"

Or, if $Computer is not the name of the computer, check the properties of $ADComputer object, in the interactive shell, and find the appropriate one, which is the name of the computer. (Could be $ADComputer.Name for example.

Upvotes: 3

Related Questions