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"
All done!
hi, this happens because PSDrive for CMSite is not mapped. i know how to do it using Console as you mentioned in your post, but any one know how to do it using powershell command, i tried - new-psdrive command to map the drive but getting a null reference exception. any help will be much appreciated.
ReplyDeleteGreat post, helped a lot. I had the same problem on 2012 R2 but seems you need to do this every time the server has been rebooted.
ReplyDeleteEnsure that your SCCM console is installed on the machine you want to run the PowerShell command from. Open the console once to get data in the registry. Then, add these lines to your powershell script:
ReplyDeleteimport-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
$PSD = Get-PSDrive -PSProvider CMSite
CD "$($PSD):"
Good idea:
DeleteImport-Module ((Split-Path $env:SMS_ADMIN_UI_PATH)+"\ConfigurationManager.psd1")
works also
The point is to to do this without the SCCM console installed. but thanks for pointing out the obvious
DeleteExcellent, it totally worked here. i could easily export DCM baseline!
Deletedont forget to put colon after the psdrive name --> cd YourSiteCode:
ReplyDelete,it took me a while :-)
Link exchange is nothing else except it is just placing the other person's website link on your page at proper place and other person will also do similar in favor of you.My site will be special with you สล็อ
ReplyDelete