xxiv
Contents
Working with Active Directory Using ADSI and PowerShell
Chapter 24:
. . . 557
A Quick Introduction to Active Directory ........................................................................ 557
Directory activities ................................................................................................. 558
Caution ................................................................................................................... 558
PowerShell and ADSI .............................................................................................. 559
Getting Entries from AD with [ADSI] ............................................................................... 559
Creating Objects ...............................................................................................................563
Getting Directory Entries with the Searcher .....................................................................564
It’s a date Jim, but not as we know it ......................................................................567
LDAP fi lters ...........................................................................................................568
Building a library of AD functions .......................................................................... 570
Finding related entries in AD ................................................................................572
Operations on Directory Entries ...................................................................................... 574
Creating objects ..................................................................................................... 574
Setting single-valued properties .............................................................................. 575
User Account Control flags ........................................................................... 576
Setting passwords .........................................................................................577
Setting group types .......................................................................................577
Adding to (and deleting from) multivalued properties ............................................ 578
Moving and deleting objects ................................................................................... 578
Testing for the presence of an entry ........................................................................ 579
Summary .......................................................................................................................... 579
Working with WMI in PowerShell
Chapter 25:
. . . . . . . . . . . . . . . . . . . . . . . 581
Displaying WMI Information ...........................................................................................583
Querying WMI .................................................................................................................586
Choosing to how to write the query .......................................................................587
Finding WMI objects by association ......................................................................588
The WMI Type Accelerators ..................................................................................592
Querying Across Computers ............................................................................................594
Logging on to the remote computer ..............................................................595
Discovering WMI Objects ...............................................................................................596
WMI Object Properties.....................................................................................................596
Updating WMI Objects ...................................................................................................597
WMI Object Methods .......................................................................................................599
A Case Study for WMI: Server 2008 Hyper-V ..................................................................600
Summary ..........................................................................................................................602
Part V: Windows Scripting Libraries
Library: File-System Utilities
Chapter 26:
. . . . . . . . . . . . . . . . . . . . . . . . . . . 607
Examining the File-System Utility Library .......................................................................607
Using the File-System Utility Library ............................................................................... 618
Using GetSubFolders, GetFiles, and GetFolderContents ......................................... 619
Using CheckExists ..................................................................................................620
86804ftoc.indd xxiv
86804ftoc.indd xxiv
1/22/09 11:53:41 AM
1/22/09 11:53:41 AM
xxv
Contents
Using GetInfo, GetSize, and GetType .....................................................................620
Setting and clearing fi le attributes ..........................................................................620
Working
with special folders, shortcuts, and menus .............................................. 621
Managing menu options .........................................................................................623
Adding to the desktop and Start menu ...................................................................625
Using NewFolder and NewFile ............................................................................... 627
Using DeleteFile, DeleteFolder, and DeleteShortcut ................................................628
Summary ..........................................................................................................................628
Library: I/O Utilities
Chapter 27:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
Examining the I/O Utility Library .................................................................................... 629
Using the I/O Utility Library ............................................................................................634
Handling fi le I/O with the utility library ................................................................634
Handling other I/O tasks with the utility library ....................................................636
Summary ..........................................................................................................................638
Library: Network Resource Utilities
Chapter 28:
. . . . . . . . . . . . . . . . . . . . . 639
Examining the Network Resource Utility Library ............................................................639
Using the Network Resource Utility Library ..................................................................... 651
Using GetDriveInfo ................................................................................................. 651
Using CheckFreeSpace ...........................................................................................652
Using MapDrive ...................................................................................................... 653
Working with printers ............................................................................................ 653
Viewing, checking, and managing services ............................................................654
Using checkRS and viewDetailedRS .......................................................................656
Using viewShareInfo, createShare, and deleteShare ................................................ 657
Summary .......................................................................................................................... 657
Library: Account Management Utilities
Chapter 29:
. . . . . . . . . . . . . . . . . . 659
Building the Account Management Library ......................................................................659
Using the Account Management Utilities .........................................................................677
Confi guring domain account policies with the library utilities ..............................677
Managing groups with the library utilities ............................................................. 678
Managing users with the library utilities ................................................................680
Managing computers with the library utilities ........................................................682
Functions for renaming and moving accounts ........................................................684
Summary ..........................................................................................................................684
Library: Building a PowerShell Library
Chapter 30:
. . . . . . . . . . . . . . . . . . . 685
Customizing Your PowerShell Environment .....................................................................685
Exploring the PowerShell host ................................................................................687
The PowerShell Prompt ..........................................................................................689
Adding more to the environment ............................................................................689
A Generic “choose” Function ........................................................................................... 691
Network Utilities ..............................................................................................................693
Finding Network adapters ......................................................................................693
86804ftoc.indd xxv
86804ftoc.indd xxv
1/22/09 11:53:41 AM
1/22/09 11:53:41 AM