private void AddDefaultDrives(CmdletProvider providerInstance, ProviderRuntime runtime) { DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider; if (driveProvider == null) { return; } var drives = driveProvider.InitializeDefaultDrives(runtime); if (drives == null) { throw new PSInvalidOperationException("The default drive collection for this null!"); } if (drives.Count == 0) { drives = providerInstance.GetDriveFromProviderInfo(); } foreach (PSDriveInfo driveInfo in drives) { if (driveInfo == null) { continue; } try { // always to global scope // use NewSkipInit because the dafault drives are inited _sessionState.RootSessionState.Drive.NewSkipInit(driveInfo, SessionStateScope<PSDriveInfo>.ScopeSpecifiers.Global.ToString()); } catch { // TODO: What should we do if the drive name is not unique? // => I guess overwrite the old one and write a warning (however this works from here) } } }