protected override PSDriveInfo?NewDrive(PSDriveInfo drive) { if (drive is CimPSDriveInfo) { return(drive); } var cimSession = (DynamicParameters as RuntimeDefinedParameterDictionary)?["CimSession"].Value as CimSession; bool createdSession = false; if (cimSession is null) { cimSession = CimSession.Create(drive.Root); createdSession = true; } if (cimSession.ComputerName != drive.Root) { if (createdSession) { cimSession.Dispose(); } WriteError(new ErrorRecord( new ArgumentException(), "DriveRootCimSessionMismatch", ErrorCategory.InvalidArgument, createdSession ? null : cimSession) { ErrorDetails = new ErrorDetails($"The computer name of the CIM session provided ('{cimSession.ComputerName}') does not match the drive root of the drive created ('{drive.Root}').") }); return(null); } var cimDrive = new CimPSDriveInfo(drive, cimSession); return(base.NewDrive(cimDrive)); }
protected override Collection <PSDriveInfo> InitializeDefaultDrives() { var currentDrive = new CimPSDriveInfo(CimSession.Create(null), "LocalCim", ProviderInfo, Environment.MachineName, "Access to the local CIM.", Credential); return(new Collection <PSDriveInfo>() { currentDrive }); }