I have a couple powershell scripts used to deleted out contacts then import them back in to a list of users. We had these scrips locally on the exchange server but wanted to consolidate so we moved them all to a central location. However since doing that one of them stopped working with a access denied error. For example the following:
New-MailboxInportRequest -Mailbox OurUser -FilePath "\\Server1\Share\Scripts and Commands\Contacts.pst" -TargetRootFolder "Contacts"
This fails with a
Unable to open PST file '\Server1\Share\Scripts and Commands\Contacts.pst'. Error details: Access to the path is denied
If we move the files to the mail servers local drive we can call it just fine. The weird part is this command which is using a Import-csv to the exact same server location has no issues:
foreach ($i in (Import-Csv "\\Server1\Share\Scripts and Commands\AutoContacts.txt")) { Search-Mailbox -Identity $i.alias -SearchQuery 'kind:contacts AND subject:" - CompanyName"' -DeleteContent }
I have verified permissions are correct and even tried adding the user I am running the Exchange PowerShell commands with explicitly to the share but still access denied. For testing we tried this also:
Get-ChiltItem "\\Server1\Share\Scripts and Commands"
It returns the directory list correctly. We have tried shortening the name and removing the quotes and that didn't matter. I even threw a hail Mary and gave the user Everyone read only permission and still nothing. Any ideas why the FilePath command doesn't work but both the Get-ChileItem and Import-Csv do? Worst case part of the script will be to copy the file locally, use it, then delete it, but I'm hoping there can be a better answer.