3. Bölüm - Nesneleri, özellikleri ve yöntemleri bulma
Bilgisayarlara ilk kez bir Commodore 64 tanıtıldı, ancak ilk modern bilgisayarım 1 megabayt belleğe sahip 286 12 Mhz IBM kopyası, 40 megabaytlık sabit sürücü ve Microsoft DOS 3.3 çalıştıran bir CGA monitöre sahip bir 5-1/4 inç disket sürücüsü oldu.
Benim gibi birçok BT Uzmanı komut satırına yabancı değildir, ancak nesnelerin, özelliklerin ve yöntemlerin konusu ortaya çıktığında, farlardaki geyiklere bakar ve "Geliştirici değilim" derler. Tahmin et ne? PowerShell ile başarılı olmak için geliştirici olmanız gerekmez. Terminolojide tıkanma. Başlangıçta her şey anlamlı olmayabilir, ancak küçük bir uygulamalı deneyimden sonra bu "ampul" anlarını yaşamaya başlayacaksınız. "Aha! Yani kitap bundan bahsediyordu."
Bu uygulamalı deneyimin bir kısmını elde etmek için bilgisayarınızdaki örnekleri denemeyi unutmayın.
Gereksinimler
Active Directory PowerShell modülü, bu bölümde gösterilen bazı örnekler için gereklidir. Modül, Windows için Uzak Sunucu Yönetici Dağıtım Araçları'nın (RSAT) bir parçasıdır. Windows'un 1809 (veya üzeri) derlemesi için RSAT araçları bir Windows özelliği olarak yüklenir. Active Directory desteği Windows Home'da kullanılamaz.
- RSAT araçlarını yükleme hakkında bilgi için bkz . Windows Yönetim modülleri.
- Windows'un eski sürümleri için bkz . Windows için RSAT.
Get-Member
Get-Member
komutlar için hangi nesnelerin, özelliklerin ve yöntemlerin kullanılabilir olduğunu keşfetmenize yardımcı olur.
Nesne tabanlı çıkış üreten tüm komutlar adresine Get-Member
aktarılabilir. Özellik, bir öğeyle ilgili bir özelliktir. Sürücü lisansınızın göz rengi adlı bir özelliği vardır ve bu özellik için en yaygın değerler mavi ve kahverengidir. Yöntem, bir öğe üzerinde gerçekleştirilebilecek bir eylemdir. Sürücü belgesi örneğinde, motorlu taşıtlar departmanı sürücü lisansınızı iptal ettiğinden yöntemlerden biri "İptal Et" şeklindedir.
Properties
Aşağıdaki örnekte, bilgisayarımda çalışan Windows Saat hizmeti hakkındaki bilgileri alacağım.
Get-Service -Name w32time
Status Name DisplayName
------ ---- -----------
Running w32time Windows Time
Status, Name ve DisplayName , önceki sonuç kümesinde gösterildiği gibi özelliklere örnektir. Status özelliğinin değeri, Running
Name özelliğinin değeri , w32time
DisplayName değeri ise şeklindedirWindows Time
.
Şimdi aynı komutu ' a aktaracağım Get-Member
:
Get-Service -Name w32time | Get-Member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Name AliasProperty Name = ServiceName
RequiredServices AliasProperty RequiredServices = ServicesDependedOn
Disposed Event System.EventHandler Disposed(System.Object, Sy...
Close Method void Close()
Continue Method void Continue()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(ty...
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
ExecuteCommand Method void ExecuteCommand(int command)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
Pause Method void Pause()
Refresh Method void Refresh()
Start Method void Start(), void Start(string[] args)
Stop Method void Stop()
WaitForStatus Method void WaitForStatus(System.ServiceProcess.Servi...
CanPauseAndContinue Property bool CanPauseAndContinue {get;}
CanShutdown Property bool CanShutdown {get;}
CanStop Property bool CanStop {get;}
Container Property System.ComponentModel.IContainer Container {get;}
DependentServices Property System.ServiceProcess.ServiceController[] Depe...
DisplayName Property string DisplayName {get;set;}
MachineName Property string MachineName {get;set;}
ServiceHandle Property System.Runtime.InteropServices.SafeHandle Serv...
ServiceName Property string ServiceName {get;set;}
ServicesDependedOn Property System.ServiceProcess.ServiceController[] Serv...
ServiceType Property System.ServiceProcess.ServiceType ServiceType ...
Site Property System.ComponentModel.ISite Site {get;set;}
StartType Property System.ServiceProcess.ServiceStartMode StartTy...
Status Property System.ServiceProcess.ServiceControllerStatus ...
ToString ScriptMethod System.Object ToString();
Önceki örnekteki sonuçların ilk satırı çok önemli bilgilerin bir parçasını içerir. TypeName size döndürülen nesne türünü bildirir. Bu örnekte bir System.ServiceProcess.ServiceController nesnesi döndürülmüştür. Bu genellikle TypeName'in son dönemden hemen sonraki bölümü olarak kısaltılır; Bu örnekte ServiceController.
Bir komutun ne tür bir nesne ürettiğini öğrendikte, bu tür bir nesneyi giriş olarak kabul eden komutları bulmak için bu bilgileri kullanabilirsiniz.
Get-Command -ParameterType ServiceController
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-Service 3.1.0.0 Microsof...
Cmdlet Restart-Service 3.1.0.0 Microsof...
Cmdlet Resume-Service 3.1.0.0 Microsof...
Cmdlet Set-Service 3.1.0.0 Microsof...
Cmdlet Start-Service 3.1.0.0 Microsof...
Cmdlet Stop-Service 3.1.0.0 Microsof...
Cmdlet Suspend-Service 3.1.0.0 Microsof...
Bu komutların tümü, işlem hattına, parametre girişlerine veya her ikisine göre ServiceController nesne türünü kabul eden bir parametreye sahiptir.
Varsayılan olarak görüntülenenden daha fazla özellik olduğuna dikkat edin. Bu ek özellikler varsayılan olarak görüntülenmese de, komut cmdlet'ine Select-Object
geçirilerek ve Property parametresi kullanılarak işlem hattından seçilebilir. Aşağıdaki örnek, 'nin sonuçlarını Get-Service
Select-Object
ekleyerek ve Özellik parametresinin değeri olarak joker karakteri belirterek *
tüm özellikleri seçer.
Get-Service -Name w32time | Select-Object -Property *
Name : w32time
RequiredServices : {}
CanPauseAndContinue : False
CanShutdown : True
CanStop : True
DisplayName : Windows Time
DependentServices : {}
MachineName : .
ServiceName : w32time
ServicesDependedOn : {}
ServiceHandle : SafeServiceHandle
Status : Running
ServiceType : Win32ShareProcess
StartType : Manual
Site :
Container :
Belirli özellikler, Property parametresinin değeri için virgülle ayrılmış bir liste kullanılarak da seçilebilir.
Get-Service -Name w32time | Select-Object -Property Status, Name, DisplayName, ServiceType
Status Name DisplayName ServiceType
------ ---- ----------- -----------
Running w32time Windows Time Win32ShareProcess
Varsayılan olarak, tabloda dört özellik döndürülür ve bir listede beş veya daha fazla özellik döndürülür. Bazı komutlar, bir tabloda varsayılan olarak kaç özelliğin görüntüleneceğini geçersiz kılmak için özel biçimlendirme kullanır.
Bu varsayılanları el ile geçersiz kılmak için kullanılabilecek birkaç Format-*
cmdlet vardır. En yaygın olanlar ve Format-List
'tir Format-Table
ve bunların her ikisi de önümüzdeki bir bölümde ele alınacaktır.
ile özellik adları Select-Object
belirtilirken joker karakterler kullanılabilir.
Get-Service -Name w32time | Select-Object -Property Status, DisplayName, Can*
Status : Running
DisplayName : Windows Time
CanPauseAndContinue : False
CanShutdown : True
CanStop : True
Önceki örnekte, Can*
ile Can
başlayan tüm özellikleri döndürmek için Property parametresinin değerlerinden biri olarak kullanılmıştır. Bunlar CanPauseAndContinue, CanShutdown ve CanStop'dur.
Yöntemler
Yöntemler, gerçekleştirilebilecek bir eylemdir. Sonuçlarını yalnızca için yöntemlerini gösterecek şekilde daraltmak Get-Member
için Get-Service
MemberType parametresini kullanın.
Get-Service -Name w32time | Get-Member -MemberType Method
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Close Method void Close()
Continue Method void Continue()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type ...
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
ExecuteCommand Method void ExecuteCommand(int command)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
Pause Method void Pause()
Refresh Method void Refresh()
Start Method void Start(), void Start(string[] args)
Stop Method void Stop()
WaitForStatus Method void WaitForStatus(System.ServiceProcess.ServiceC...
Gördüğünüz gibi birçok yöntem vardır. Bir Windows hizmetini durdurmak için Stop yöntemi kullanılabilir.
(Get-Service -Name w32time).Stop()
Şimdi Windows saat hizmetinin gerçekten durdurulduğunu doğrulamak için.
Get-Service -Name w32time
Status Name DisplayName
------ ---- -----------
Stopped w32time Windows Time
Kendimi yöntemleri kullanırken nadiren bulurum, ama bunlar farkında olmanız gereken bir şey. Bu öğeyi değiştirmek için karşılık gelen bir komut olmadan bir Get-*
komutla karşılaşabileceğiniz zamanlar vardır.
Genellikle, bir yöntem onu değiştiren bir eylem gerçekleştirmek için kullanılabilir. Get-SqlAgentJob
SqlServer PowerShell modülündeki cmdlet bunun iyi bir örneğidir. Modül, SQL Server Management Studio'nun (SMSS) bir parçası olarak yüklenir. Karşılık gelen Set-*
cmdlet yoktur, ancak aynı görevi tamamlamak için bir yöntem kullanılabilir.
Yöntemlerin farkında olmanın bir diğer nedeni de, birçok yeni başlayanlar komutlarla Get-*
yıkıcı değişiklikler yapılamabileceğini varsaymaktır. Ancak uygunsuz kullanıldığında ciddi sorunlara neden olabilirler.
Daha iyi bir seçenek, varsa eylemi gerçekleştirmek için bir cmdlet kullanmaktır. Devam edin ve Windows Saat hizmetini başlatın, ancak bu kez hizmetleri başlatmak için cmdlet'ini kullanın.
Get-Service -Name w32time | Start-Service -PassThru
Status Name DisplayName
------ ---- -----------
Running w32time Windows Time
Varsayılan olarak, Start-Service
aynı başlangıç yöntemi Get-Service
gibi herhangi bir sonuç döndürmez.
Ancak cmdlet kullanmanın avantajlarından biri, cmdlet'in birçok kez bir yöntemle kullanılamayabilecek ek işlevler sun olmasıdır. Önceki örnekte PassThru parametresi kullanılmıştır. Bu, normalde çıkış üretmeyen bir cmdlet'in çıkış üretmesine neden olur.
Bir cmdlet'in çıkışıyla ilgili varsayımlara dikkat edin. Bir şeyler varsaydığında ne olacağını hepimiz biliyoruz. Windows 10 laboratuvar ortamı bilgisayarımda çalışan PowerShell işlemi hakkında bilgi alacağım.
Get-Process -Name PowerShell
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
922 48 107984 140552 2.84 9020 1 powershell
Şimdi aynı komutu Get-Member'a aktaracağım:
Get-Process -Name PowerShell | Get-Member
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Handles AliasProperty Handles = Handlecount
Name AliasProperty Name = ProcessName
NPM AliasProperty NPM = NonpagedSystemMemorySize64
PM AliasProperty PM = PagedMemorySize64
SI AliasProperty SI = SessionId
VM AliasProperty VM = VirtualMemorySize64
WS AliasProperty WS = WorkingSet64
Disposed Event System.EventHandler Disposed(System.Object, ...
ErrorDataReceived Event System.Diagnostics.DataReceivedEventHandler ...
Exited Event System.EventHandler Exited(System.Object, Sy...
OutputDataReceived Event System.Diagnostics.DataReceivedEventHandler ...
BeginErrorReadLine Method void BeginErrorReadLine()
BeginOutputReadLine Method void BeginOutputReadLine()
CancelErrorRead Method void CancelErrorRead()
CancelOutputRead Method void CancelOutputRead()
Close Method void Close()
CloseMainWindow Method bool CloseMainWindow()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(...
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()
Kill Method void Kill()
Refresh Method void Refresh()
Start Method bool Start()
ToString Method string ToString()
WaitForExit Method bool WaitForExit(int milliseconds), void Wai...
WaitForInputIdle Method bool WaitForInputIdle(int milliseconds), boo...
__NounName NoteProperty string __NounName=Process
BasePriority Property int BasePriority {get;}
Container Property System.ComponentModel.IContainer Container {...
EnableRaisingEvents Property bool EnableRaisingEvents {get;set;}
ExitCode Property int ExitCode {get;}
ExitTime Property datetime ExitTime {get;}
Handle Property System.IntPtr Handle {get;}
HandleCount Property int HandleCount {get;}
HasExited Property bool HasExited {get;}
Id Property int Id {get;}
MachineName Property string MachineName {get;}
MainModule Property System.Diagnostics.ProcessModule MainModule ...
MainWindowHandle Property System.IntPtr MainWindowHandle {get;}
MainWindowTitle Property string MainWindowTitle {get;}
MaxWorkingSet Property System.IntPtr MaxWorkingSet {get;set;}
MinWorkingSet Property System.IntPtr MinWorkingSet {get;set;}
Modules Property System.Diagnostics.ProcessModuleCollection M...
NonpagedSystemMemorySize Property int NonpagedSystemMemorySize {get;}
NonpagedSystemMemorySize64 Property long NonpagedSystemMemorySize64 {get;}
PagedMemorySize Property int PagedMemorySize {get;}
PagedMemorySize64 Property long PagedMemorySize64 {get;}
PagedSystemMemorySize Property int PagedSystemMemorySize {get;}
PagedSystemMemorySize64 Property long PagedSystemMemorySize64 {get;}
PeakPagedMemorySize Property int PeakPagedMemorySize {get;}
PeakPagedMemorySize64 Property long PeakPagedMemorySize64 {get;}
PeakVirtualMemorySize Property int PeakVirtualMemorySize {get;}
PeakVirtualMemorySize64 Property long PeakVirtualMemorySize64 {get;}
PeakWorkingSet Property int PeakWorkingSet {get;}
PeakWorkingSet64 Property long PeakWorkingSet64 {get;}
PriorityBoostEnabled Property bool PriorityBoostEnabled {get;set;}
PriorityClass Property System.Diagnostics.ProcessPriorityClass Prio...
PrivateMemorySize Property int PrivateMemorySize {get;}
PrivateMemorySize64 Property long PrivateMemorySize64 {get;}
PrivilegedProcessorTime Property timespan PrivilegedProcessorTime {get;}
ProcessName Property string ProcessName {get;}
ProcessorAffinity Property System.IntPtr ProcessorAffinity {get;set;}
Responding Property bool Responding {get;}
SafeHandle Property Microsoft.Win32.SafeHandles.SafeProcessHandl...
SessionId Property int SessionId {get;}
Site Property System.ComponentModel.ISite Site {get;set;}
StandardError Property System.IO.StreamReader StandardError {get;}
StandardInput Property System.IO.StreamWriter StandardInput {get;}
StandardOutput Property System.IO.StreamReader StandardOutput {get;}
StartInfo Property System.Diagnostics.ProcessStartInfo StartInf...
StartTime Property datetime StartTime {get;}
SynchronizingObject Property System.ComponentModel.ISynchronizeInvoke Syn...
Threads Property System.Diagnostics.ProcessThreadCollection T...
TotalProcessorTime Property timespan TotalProcessorTime {get;}
UserProcessorTime Property timespan UserProcessorTime {get;}
VirtualMemorySize Property int VirtualMemorySize {get;}
VirtualMemorySize64 Property long VirtualMemorySize64 {get;}
WorkingSet Property int WorkingSet {get;}
WorkingSet64 Property long WorkingSet64 {get;}
PSConfiguration PropertySet PSConfiguration {Name, Id, PriorityClass, Fi...
PSResources PropertySet PSResources {Name, Id, Handlecount, WorkingS...
Company ScriptProperty System.Object Company {get=$this.Mainmodule....
CPU ScriptProperty System.Object CPU {get=$this.TotalProcessorT...
Description ScriptProperty System.Object Description {get=$this.Mainmod...
FileVersion ScriptProperty System.Object FileVersion {get=$this.Mainmod...
Path ScriptProperty System.Object Path {get=$this.Mainmodule.Fil...
Product ScriptProperty System.Object Product {get=$this.Mainmodule....
ProductVersion ScriptProperty System.Object ProductVersion {get=$this.Main...
Varsayılan olarak görüntülenenden daha fazla özellik listelendiğine dikkat edin. Görüntülenen varsayılan özelliklerin bir kısmı, sonuçlarını Get-Member
görüntülerken özellik olarak gösterilmez. Bunun nedeni , PM(K)
, WS(K)
ve CPU(s)
gibi NPM(K)
görüntülenen değerlerin çoğunun hesaplanmış özellikler olmasıdır. Gerçek özellik adlarını belirlemek için komutuna Get-Member
yöneltilmelidir.
Bir komut çıkış üretmezse, komutuna Get-Member
kanalı oluşturulamaz. Start-Service
Varsayılan olarak herhangi bir çıkış üretmediğinden, öğesine yöneltmeye Get-Member
çalıştığınızda bir hata oluşturur.
Start-Service -Name w32time | Get-Member
Get-Member : You must specify an object for the Get-Member cmdlet.
At line:1 char:31
+ Start-Service -Name w32time | Get-Member
+
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMembe
rCommand
PassThru parametresi, cmdlet'iyle Start-Service
belirtilebilir ve çıkış üretmesini sağlar ve bu parametre hatasız olarak iletilirGet-Member
.
Start-Service -Name w32time -PassThru | Get-Member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Name AliasProperty Name = ServiceName
RequiredServices AliasProperty RequiredServices = ServicesDependedOn
Disposed Event System.EventHandler Disposed(System.Object, Sy...
Close Method void Close()
Continue Method void Continue()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(ty...
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
ExecuteCommand Method void ExecuteCommand(int command)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
Pause Method void Pause()
Refresh Method void Refresh()
Start Method void Start(), void Start(string[] args)
Stop Method void Stop()
WaitForStatus Method void WaitForStatus(System.ServiceProcess.Servi...
CanPauseAndContinue Property bool CanPauseAndContinue {get;}
CanShutdown Property bool CanShutdown {get;}
CanStop Property bool CanStop {get;}
Container Property System.ComponentModel.IContainer Container {get;}
DependentServices Property System.ServiceProcess.ServiceController[] Depe...
DisplayName Property string DisplayName {get;set;}
MachineName Property string MachineName {get;set;}
ServiceHandle Property System.Runtime.InteropServices.SafeHandle Serv...
ServiceName Property string ServiceName {get;set;}
ServicesDependedOn Property System.ServiceProcess.ServiceController[] Serv...
ServiceType Property System.ServiceProcess.ServiceType ServiceType ...
Site Property System.ComponentModel.ISite Site {get;set;}
StartType Property System.ServiceProcess.ServiceStartMode StartTy...
Status Property System.ServiceProcess.ServiceControllerStatus ...
ToString ScriptMethod System.Object ToString();
öğesine yöneltmek için Get-Member
, bir komutun nesne tabanlı çıkış üretmesi gerekir.
Get-Service -Name w32time | Out-Host | Get-Member
Status Name DisplayName
------ ---- -----------
Running w32time Windows Time
Get-Member : You must specify an object for the Get-Member cmdlet.
At line:1 char:40
+ Get-Service -Name w32time | Out-Host | Get-Member
+
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
Out-Host
doğrudan PowerShell konağına yazar, ancak işlem hattı için nesne tabanlı çıkış üretmez. Bu nedenle adresine boruyla Get-Member
bağlanamaz.
Active Directory
Not
Bu bölümün gereksinimler bölümünde listelenen Uzak Sunucu Yönetici Dağıtım Araçları bu bölümü tamamlamak için gereklidir. Ayrıca, bu kitaba girişte belirtildiği gibi, Windows 10 laboratuvar ortamı bilgisayarınızın laboratuvar ortamı etki alanının bir üyesi olması gerekir.
Uzak sunucu yönetim araçları yüklendiğinde ActiveDirectory PowerShell modülünün parçası olarak hangi komutların eklendiğini belirlemek için Module parametresiyle kullanın.Get-Command
Get-Command -Module ActiveDirectory
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-ADCentralAccessPolicyMember 1.0.0.0 ActiveDi...
Cmdlet Add-ADComputerServiceAccount 1.0.0.0 ActiveDi...
Cmdlet Add-ADDomainControllerPasswordReplicationPolicy 1.0.0.0 ActiveDi...
Cmdlet Add-ADFineGrainedPasswordPolicySubject 1.0.0.0 ActiveDi...
Cmdlet Add-ADGroupMember 1.0.0.0 ActiveDi...
Cmdlet Add-ADPrincipalGroupMembership 1.0.0.0 ActiveDi...
Cmdlet Add-ADResourcePropertyListMember 1.0.0.0 ActiveDi...
Cmdlet Clear-ADAccountExpiration 1.0.0.0 ActiveDi...
Cmdlet Clear-ADClaimTransformLink 1.0.0.0 ActiveDi...
Cmdlet Disable-ADAccount 1.0.0.0 ActiveDi...
...
ActiveDirectory PowerShell modülünün bir parçası olarak toplam 147 komut eklendi. Bu komutların bazı komutları varsayılan olarak kullanılabilir özelliklerin yalnızca bir bölümünü döndürür.
Bu modüldeki komutların adlarında farklı bir şey fark ettiniz mi? Komutların isim bölümü bir AD önekine sahiptir. Çoğu modülün komutlarında bunu görmek yaygın bir durumdur. Ön ek, adlandırma çakışmalarını önlemeye yardımcı olmak için tasarlanmıştır.
Get-ADUser -Identity mike | Get-Member
TypeName: Microsoft.ActiveDirectory.Management.ADUser
Name MemberType Definition
---- ---------- ----------
Contains Method bool Contains(string propertyName)
Equals Method bool Equals(System.Object obj)
GetEnumerator Method System.Collections.IDictionaryEnumerator GetEn...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Item ParameterizedProperty Microsoft.ActiveDirectory.Management.ADPropert...
DistinguishedName Property System.String DistinguishedName {get;set;}
Enabled Property System.Boolean Enabled {get;set;}
GivenName Property System.String GivenName {get;set;}
Name Property System.String Name {get;}
ObjectClass Property System.String ObjectClass {get;set;}
ObjectGUID Property System.Nullable`1[[System.Guid, mscorlib, Vers...
SamAccountName Property System.String SamAccountName {get;set;}
SID Property System.Security.Principal.SecurityIdentifier S...
Surname Property System.String Surname {get;set;}
UserPrincipalName Property System.String UserPrincipalName {get;set;}
Active Directory'yi yalnızca belirsiz bir şekilde biliyor olsanız bile, bir kullanıcı hesabının bu örnekte gösterilenden daha fazla özelliğe sahip olduğunu muhtemelen biliyorsunuzdur.
Cmdlet,döndürmek Get-ADUser
istediğiniz ek (varsayılan olmayan) özellikleri belirtmek için kullanılan bir Properties parametresine sahiptir. Joker karakter belirtilmesi *
bunların tümünü döndürür.
Get-ADUser -Identity mike -Properties * | Get-Member
TypeName: Microsoft.ActiveDirectory.Management.ADUser
Name MemberType Definition
---- ---------- ----------
Contains Method bool Contains(string proper...
Equals Method bool Equals(System.Object obj)
GetEnumerator Method System.Collections.IDiction...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Item ParameterizedProperty Microsoft.ActiveDirectory.M...
AccountExpirationDate Property System.DateTime AccountExpi...
accountExpires Property System.Int64 accountExpires...
AccountLockoutTime Property System.DateTime AccountLock...
AccountNotDelegated Property System.Boolean AccountNotDe...
AllowReversiblePasswordEncryption Property System.Boolean AllowReversi...
AuthenticationPolicy Property Microsoft.ActiveDirectory.M...
AuthenticationPolicySilo Property Microsoft.ActiveDirectory.M...
BadLogonCount Property System.Int32 BadLogonCount ...
badPasswordTime Property System.Int64 badPasswordTim...
badPwdCount Property System.Int32 badPwdCount {g...
CannotChangePassword Property System.Boolean CannotChange...
CanonicalName Property System.String CanonicalName...
Certificates Property Microsoft.ActiveDirectory.M...
City Property System.String City {get;set;}
CN Property System.String CN {get;}
codePage Property System.Int32 codePage {get;...
Company Property System.String Company {get;...
CompoundIdentitySupported Property Microsoft.ActiveDirectory.M...
Country Property System.String Country {get;...
countryCode Property System.Int32 countryCode {g...
Created Property System.DateTime Created {get;}
createTimeStamp Property System.DateTime createTimeS...
Deleted Property System.Boolean Deleted {get;}
Department Property System.String Department {g...
Description Property System.String Description {...
DisplayName Property System.String DisplayName {...
DistinguishedName Property System.String Distinguished...
Division Property System.String Division {get...
DoesNotRequirePreAuth Property System.Boolean DoesNotRequi...
dSCorePropagationData Property Microsoft.ActiveDirectory.M...
EmailAddress Property System.String EmailAddress ...
EmployeeID Property System.String EmployeeID {g...
EmployeeNumber Property System.String EmployeeNumbe...
Enabled Property System.Boolean Enabled {get...
Fax Property System.String Fax {get;set;}
GivenName Property System.String GivenName {ge...
HomeDirectory Property System.String HomeDirectory...
HomedirRequired Property System.Boolean HomedirRequi...
HomeDrive Property System.String HomeDrive {ge...
HomePage Property System.String HomePage {get...
HomePhone Property System.String HomePhone {ge...
Initials Property System.String Initials {get...
instanceType Property System.Int32 instanceType {...
isDeleted Property System.Boolean isDeleted {g...
KerberosEncryptionType Property Microsoft.ActiveDirectory.M...
LastBadPasswordAttempt Property System.DateTime LastBadPass...
LastKnownParent Property System.String LastKnownPare...
lastLogoff Property System.Int64 lastLogoff {ge...
lastLogon Property System.Int64 lastLogon {get...
LastLogonDate Property System.DateTime LastLogonDa...
lastLogonTimestamp Property System.Int64 lastLogonTimes...
LockedOut Property System.Boolean LockedOut {g...
logonCount Property System.Int32 logonCount {ge...
LogonWorkstations Property System.String LogonWorkstat...
Manager Property System.String Manager {get;...
MemberOf Property Microsoft.ActiveDirectory.M...
MNSLogonAccount Property System.Boolean MNSLogonAcco...
MobilePhone Property System.String MobilePhone {...
Modified Property System.DateTime Modified {g...
modifyTimeStamp Property System.DateTime modifyTimeS...
msDS-User-Account-Control-Computed Property System.Int32 msDS-User-Acco...
Name Property System.String Name {get;}
nTSecurityDescriptor Property System.DirectoryServices.Ac...
ObjectCategory Property System.String ObjectCategor...
ObjectClass Property System.String ObjectClass {...
ObjectGUID Property System.Nullable`1[[System.G...
objectSid Property System.Security.Principal.S...
Office Property System.String Office {get;s...
OfficePhone Property System.String OfficePhone {...
Organization Property System.String Organization ...
OtherName Property System.String OtherName {ge...
PasswordExpired Property System.Boolean PasswordExpi...
PasswordLastSet Property System.DateTime PasswordLas...
PasswordNeverExpires Property System.Boolean PasswordNeve...
PasswordNotRequired Property System.Boolean PasswordNotR...
POBox Property System.String POBox {get;set;}
PostalCode Property System.String PostalCode {g...
PrimaryGroup Property System.String PrimaryGroup ...
primaryGroupID Property System.Int32 primaryGroupID...
PrincipalsAllowedToDelegateToAccount Property Microsoft.ActiveDirectory.M...
ProfilePath Property System.String ProfilePath {...
ProtectedFromAccidentalDeletion Property System.Boolean ProtectedFro...
pwdAnswer Property System.String pwdAnswer {ge...
pwdLastSet Property System.Int64 pwdLastSet {ge...
pwdQuestion Property System.String pwdQuestion {...
SamAccountName Property System.String SamAccountNam...
sAMAccountType Property System.Int32 sAMAccountType...
ScriptPath Property System.String ScriptPath {g...
sDRightsEffective Property System.Int32 sDRightsEffect...
ServicePrincipalNames Property Microsoft.ActiveDirectory.M...
SID Property System.Security.Principal.S...
SIDHistory Property Microsoft.ActiveDirectory.M...
SmartcardLogonRequired Property System.Boolean SmartcardLog...
sn Property System.String sn {get;set;}
State Property System.String State {get;set;}
StreetAddress Property System.String StreetAddress...
Surname Property System.String Surname {get;...
Title Property System.String Title {get;set;}
TrustedForDelegation Property System.Boolean TrustedForDe...
TrustedToAuthForDelegation Property System.Boolean TrustedToAut...
UseDESKeyOnly Property System.Boolean UseDESKeyOnl...
userAccountControl Property System.Int32 userAccountCon...
userCertificate Property Microsoft.ActiveDirectory.M...
UserPrincipalName Property System.String UserPrincipal...
uSNChanged Property System.Int64 uSNChanged {get;}
uSNCreated Property System.Int64 uSNCreated {get;}
whenChanged Property System.DateTime whenChanged...
whenCreated Property System.DateTime whenCreated...
Şimdi daha çok öyle görünüyor.
Active Directory kullanıcı hesabının özelliklerinin varsayılan olarak bu kadar sınırlı olmasının bir nedeni olabilir mi? Üretim Active Directory ortamınızdaki her kullanıcı hesabı için her özelliği döndürdünüzü düşünün. Yalnızca etki alanı denetleyicilerinin kendisi için değil, ağınız için de neden olabileceğiniz performans düşüşü düşünün. Zaten her mülke ihtiyacınız olacağından şüphelisiniz. Hangi özelliklerin mevcut olduğunu belirlemeye çalışırken tek bir kullanıcı hesabının tüm özelliklerini döndürmek son derece kabul edilebilir.
Bir komutu prototip oluştururken birçok kez çalıştırmak sık karşılaşılan bir durum değildir. Çok büyük bir sorgu gerçekleştirecekseniz bir kez sorgulayın ve sonuçları bir değişkende depolayın. Ardından, pahalı bir sorguyu tekrar tekrar kullanmak yerine değişkenin içeriğiyle çalışın.
$Users = Get-ADUser -Identity mike -Properties *
Önceki komutu çok kez çalıştırmak yerine değişkenin içeriğini $Users
kullanın.
Active Directory'de bu kullanıcıda değişiklik yapıldığında değişkenin içeriğinin güncelleştirilmiyor olduğunu unutmayın.
Kullanılabilir özellikleri bulmak için Get-Member
değişkenine yöneltebilirsiniz$Users
.
$Users | Get-Member
Ardından, active Directory'yi birden fazla kez sorgulamak zorunda kalmadan adresine ekleyerek $Users
Select-Object
tek tek özellikleri seçin.
$Users | Select-Object -Property Name, LastLogonDate, LastBadPasswordAttempt
Active Directory'yi birden çok kez sorgulayacaksanız, istediğiniz varsayılan olmayan özellikleri belirtmek için Özellikler parametresini kullanın.
Get-ADUser -Identity mike -Properties LastLogonDate, LastBadPasswordAttempt
DistinguishedName : CN=Mike F. Robbins,OU=Sales,DC=mikefrobbins,DC=com
Enabled : True
GivenName : Mike
LastBadPasswordAttempt : 2/4/2017 10:46:15 AM
LastLogonDate : 2/18/2017 12:45:14 AM
Name : Mike F. Robbins
ObjectClass : user
ObjectGUID : a82a8c58-1332-4a57-a6e2-68e0c750ea56
SamAccountName : mike
SID : S-1-5-21-2989741381-570885089-3319121794-1108
Surname : Robbins
UserPrincipalName : miker@mikefrobbins.com
Özet
Bu bölümde, bir komutun ürettiği nesne türünü belirlemeyi, bir komut için hangi özelliklerin ve yöntemlerin kullanılabilir olduğunu belirlemeyi ve varsayılan olarak döndürülen özellikleri sınırlayan komutlarla çalışmayı öğrendiniz.
İnceleyin
- Cmdlet ne tür bir nesne
Get-Process
üretir? - Bir komut için kullanılabilir özellikleri nasıl belirlersiniz?
- Aynı şeyi ayarlamak için değil de bir şey almak için bir komut varsa, neyi denetlemeniz gerekir?
- Varsayılan olarak çıkış üretmeyen bazı komutlar çıkış üretmek için nasıl yapılabilir?
- Çok büyük miktarda çıkış üreten bir komutun sonuçlarıyla çalışacaksanız ne yapmayı düşünmelisiniz?
Okuma Önerileri
PowerShell
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin