In a SharePoint 2010 project, using VS 2012, I set up a post build event:

"%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe" -version 2 -command "& {Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0; & '$(SolutionDir)somescript.ps1' -Web '$(SharePointSiteUrl)'}"

Basically, the script perform some clean up on the target sharepoint site.

This was working well with PowerShell V2 on Windows 2008 R2, but now that I'm working on Windows 2012 R2, and thus with PowerShell V3, the script does not works anymore.

I get this error:

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

There are two cases, from my understanding, that can cause this issue:

  1. The script runs in 32 bits mode (and VS is 32 bits). I solved this issue by using %WINDIR%\SysNative to target the 64 bits version event from the 32 bits process.
  2. The .Net runtime is v4. I also solved this issue by forcing PowerShell V2 with the -version 2 command line argument.

Is there any other case where this errors can appears?

How can I fix my post build event?

1 Answer 1


So simple that I missed it.

The correct syntax of the version argument is :

powershell.exe -version 2.0

Everything goes fine now...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.