In Visual Studio it's possible to edit and debug PowerShell scripts, using the PowerShell Tools for Visual Studio 2015 extension.
But even after installing the extension, debugging doesn't immediately work, as trying to do this, the output window simply shows an unauthorized access error message.
I've found the blog post PowerShell Tools for Visual Studio 2013 – unable to run and/or debug PowerShell script – execution policies problem that has helped me in finding the solution:
- from a PowerShell window with elevated privileges,
- run the command "Set-ExecutionPolicy" RemoteSigned
In the User Profile Synchronization job, the user running it must have in Active Directory the permission "Replicating Directory Changes".
By one client, there was a debate between the client itself and one of its supplier offering the AD services about if the user had this permission.
To check this, I have found a PowerShell script doing this test in Checking Replication Directory Changes for account by PowerShell.
For reference I have copied the script here: CheckRDC.ps1 (1.4KB), then you can run it with:
For my client, we have imported by error too many user profiles, so we needed to delete from the User Profile Application the user profiles in the wrong OUs.
Taken example from Delete all User Profiles in SharePoint 2010/2013 using PowerShell, we have created the following PowerShell script: DeleteUserProfilesInOU.ps1 (1.1KB)