As you may probably know, Microsoft System Center Configuration Manager includes a PowerShell module that allows us to automate our day-to-day sysadmin tasks. This module is very helpful for repetitive tasks. But if you try to schedule a PowerShell script to run as run as a Service Account, you will get an error.
cd : Cannot find drive. A drive with the name ‘CM1’ does not exist.
At line:1 char:1
+ cd CM1:
+ CategoryInfo : ObjectNotFound: (CM1:String) [Set-Location], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
First, I created the following Active Directory account: “GET-CMD\Svc_CM_Script” that will run my SCCM PowerShell Scripts. So, I run as the PowerShell console with this user.
Next, I will import the SCCM module:
PS > Import-Module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
Ok, the module is imported with no error. Now, I want to go to the newly created Configuration Manager drive but it doesn’t work! Let’s examine:
- The console is running as my service account.
- The get-module cmdlet shows me the SCCM module, so the module is imported.
- But the PSDrive is not accessible
Let’s compare with my user account. I open the PowerShell console, and run the same commands:
Well, it works.
What does it mean?
The Configuration Manager PowerShell module is digitally signed, and the service account running the PowerShell commands must install the certificate that the module was signed with because I never open the SCCM console with this service account.
How to fix this issue?
You can install the certificate to solve this problem:
- Right click the PowerShell Module called “ConfigurationManager.psd1”
- Select “Properties” and “Digital Signatures“
Finally, select “View Certificate” and “Install Certificate...” into the Trusted Publishers Store.
Once the certificate is installed, you can now run your SCCM PowerShell commands!
Thanks for reading! You can follow me on Twitter @PrigentNico