Error Switching to a Different Drive


I need to use SCCM cmlet, and it is fine if I am running the following code directly:
Import-Module “C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1”
Set-Location -path ‘ABC:’

However, when I run it under PSU, it returned:

An error occurred: Cannot find drive. A drive with the name 'ABC' does not exist.


I currently have a script that interacts with SCCM in this same manner, import the module and change to the Site drive.
I did have to make sure to assign the appropriate role in SCCM for the account used to run the script. When testing the code directly are you running as the same account that is used to run the script?

If the user does not have permissions in SCCM, the module will import but the drive will not be created.

I was running it on the same server, when I tested it, I use my credential to run it.
On the PSU, I think it runs as the system? How do you set it up on the PSU on the website to switch to the Site drive?

These are the lines I use in the beginning of the script:

Import-Module 'C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\ConfigurationManager.psd1' -Force -ErrorAction Stop

Set-Location SC1:

My PSU is running as a service account so I have added that account to SCCM with appropriate roles for what I do in SCCM. If you are not using a service account but running as system, you would need to grant these permissions to the PSU system in SCCM (PSUSERVERNAME$).

This would include roles to grant permissions to SQL if you are also running queries directly.

@Ray Thanks so much for your hint!

There is one more step to that: I have to run the PowerShell prompt from the SCCM console once for the service account. Then it will work :slight_smile:

Instead of the -Force option on the import module, I found that making sure the file itself isn’t blocked works too.

$CMModulePath = “C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\configurationmanager.psd1”

Unblock-File -Path $CMModulePath

Import-Module $CMModulePath

1 Like