Sql-server – Invoke-PolicyEvaluation fails with xml files on network location

managementpowershellsql serversql-server-2016

I am just starting to explore using Policy Based Management in SQL 2016. I created a policy that runs in SSMS just fine. I exported the policy to a folder on the local machine (VMSk1) that is shared to Everyone/read. I go to a second machine (VMSk2) and execute the following powershell. The idea was to have a central location for the xml export files and run on any server….

$Path = "\\\vmsk1\PolicyExports\AllDatabasesInSync.xml"
Invoke-PolicyEvaluation -Policy $Path -TargetServerName $env:computername

…I get the following error…

Invoke-PolicyEvaluation : File 'Microsoft.PowerShell.Core\FileSystem::\vmsk1\PolicyExports\AllDatabasesInSync.xml' does not have a valid XML format that can be deserialized to a policy.

If I copy the file to VMSk2 and run…

$Path = "c:\PolicyExports\AllDatabasesInSync.xml"
Invoke-PolicyEvaluation -Policy $Path -TargetServerName $env:computername

…the policy will execute.

I tried

$Path = "\\\vmsk2\PolicyExports\AllDatabasesInSync.xml"

and it failed.

So I am left with the conclusion that the cmdlet will not work with an xml file located anywhere but a local drive; which seems just plain wrong.

Am I missing something? Why can I not execute the policy using an xml export file from a network share?

Best Answer

Nope you are not missing anything, the command does not support use of UNC paths. At some point when the SQL Server module is published onto GitHub we might be able to help Microsoft fix that issue. However, until then you can work around it by using New-PSDrive to map it to a drive letter and that should work.