Wednesday, May 1, 2013

Solve ps-drive problem with SCCM2012 sp1 powershell script


I was trying to run a powershell script on a SCCM2012 sp1 machine and couldn't get it to work. After importing the Configuration module I just couldn't access the powershell drive. The problem only occured when trying to use a service account. With my normal admin account everything was working fine. This led me to believe  that it was access permission problems but no, that was a dead end.

Here's what i was trying to do:
Import-Module ‘c:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’
Cd ps1:
Remove-CMDevice -DeviceName $computername -force

The errors I got was:
Cannot find drive. A drive with the name 'ps1' does not exist.

This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive.

The only problem here was that "get-psdrive" didn't return any ps1: drive that i needed.

Finally I found the error. It seems that starting powershell from within the Configuration Manager Console once registers the ps-drive for the current user account. Here's how you do it

1. In Configuration Manager Console click "Connect via Windows PowerShell"

 2. Type A for "Always run"


All done!