PSBase 通常用于调用隐藏方法,如果我可以这么说的话。比如我用[ADSI]连接获取本地管理员组的一个实例,然后查看对象的成员,我看到的就是这个。
PS H:\> $admGroup = [ADSI]("WinNT://./Administrators")
PS H:\> $admGroup | gm
TypeName: System.DirectoryServices.DirectoryEntry
Name MemberType Definition
---- ---------- ----------
ConvertDNWithBinaryToString CodeMethod static string ConvertDNWithBinaryToString(psobject deInstance, psobject dnWit...
ConvertLargeIntegerToInt64 CodeMethod static long ConvertLargeIntegerToInt64(psobject deInstance, psobject largeInt...
Description Property System.DirectoryServices.PropertyValueCollection Description {get;set;}
groupType Property System.DirectoryServices.PropertyValueCollection groupType {get;set;}
Name Property System.DirectoryServices.PropertyValueCollection Name {get;set;}
objectSid Property System.DirectoryServices.PropertyValueCollection objectSid {get;set;}
您看不到 add() 方法,因为它没有在 PowerShell 中公开。这是PSBase 帮助您访问原始对象的地方。
PS H:\> $objGroup.PSBase | gm
TypeName: System.Management.Automation.PSMemberSet
Name MemberType Definition
---- ---------- ----------
Disposed Event System.EventHandler Disposed(System.Object, System.EventArgs)
Close Method void Close()
CommitChanges Method void CommitChanges()
CopyTo Method adsi CopyTo(adsi newParent), adsi CopyTo(adsi newParent, string newName)
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
DeleteTree Method void DeleteTree()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
Invoke Method System.Object Invoke(string methodName, Params System.Object[] args)
InvokeGet Method System.Object InvokeGet(string propertyName)
InvokeSet Method void InvokeSet(string propertyName, Params System.Object[] args)
MoveTo Method void MoveTo(adsi newParent), void MoveTo(adsi newParent, string newName)
RefreshCache Method void RefreshCache(), void RefreshCache(string[] propertyNames)
Rename Method void Rename(string newName)
ToString Method string ToString()
AuthenticationType Property System.DirectoryServices.AuthenticationTypes AuthenticationType {get;set;}
Children Property System.DirectoryServices.DirectoryEntries Children {get;}
Container Property System.ComponentModel.IContainer Container {get;}
Guid Property guid Guid {get;}
Name Property string Name {get;}
NativeGuid Property string NativeGuid {get;}
NativeObject Property System.Object NativeObject {get;}
ObjectSecurity Property System.DirectoryServices.ActiveDirectorySecurity ObjectSecurity {get;set;}
Options Property System.DirectoryServices.DirectoryEntryConfiguration Options {get;}
Parent Property adsi Parent {get;}
Password Property string Password {set;}
Path Property string Path {get;set;}
Properties Property System.DirectoryServices.PropertyCollection Properties {get;}
SchemaClassName Property string SchemaClassName {get;}
SchemaEntry Property adsi SchemaEntry {get;}
Site Property System.ComponentModel.ISite Site {get;set;}
UsePropertyCache Property bool UsePropertyCache {get;set;}
Username Property string Username {get;set;}
我们可以使用Invoke() 方法在这个对象上调用add 方法。您只需将Add 作为方法名和用户名作为参数传递。
因此,总而言之,PSBase 概念应该根据上下文使用。