0

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"

        }
    } 

1 Answer 1

3

$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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, or he could do: $ADComputer = Get-ADComputer $Computer | Select -Expand DNSHostName

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.