Sie sind auf Seite 1von 3

TOPIC about_Properties SHORT DESCRIPTION Describes how to use object properties in Windows PowerShell.

LONG DESCRIPTION Windows PowerShell uses structured collections of information called objects to represent the items in data stores or the state of the computer. Typically, you work with object that are part of the Microsoft .NET Framework, but you can also create custom objects in Windows PowerShell. The association between an item and its object is very close. When you change an object, you change the item that it represents. For example, when you get a file in Windows PowerShell, you do not get the actual file. Instead, you get a FileInfo object that represents the file. When you change the FileInfo object, the file changes too. Most objects have properties. Properties are the data that is associated with an object. This data describes the object. For example, a FileInfo object has a property called Length that describes the size of the file that is represented by the object. Object Properties To list the properties of an object, use the Get-Member cmdlet. For example, to get the properties of a FileInfo object, use the Get-ChildItem cmdlet to get the FileInfo object that represents a file. Then, use a pipeline operator (|) to send the FileInfo object to Get-Member. The following command gets the PowerShell.exe file and sends it to Get-Member. The $Pshome automatic variable contains the path of the Windows PowerShell installation directory. get-childitem $pshome\powershell.exe | get-member The output of the command lists the members of the FileInfo object. Members include both properties and methods. When you work in Windows PowerShell, you have access to all the members of the objects. To get only the properties of an object and not the methods, use the MemberType parameter of the Get-Member cmdlet with a value of "property", as shown in the following example. get-childitem $pshome\powershell.exe | get-member -membertype property TypeName: System.IO.FileInfo Name ---Attributes et;} CreationTime CreationTimeUtc Directory Property Property Property System.DateTime CreationTime {get;set;} System.DateTime CreationTimeUtc {get;set;} System.IO.DirectoryInfo Directory {get;} MemberType Definition ---------- ---------Property System.IO.FileAttributes Attributes {get;s

DirectoryName Exists Extension FullName IsReadOnly LastAccessTime LastAccessTimeUtc ;}

Property Property Property Property Property Property Property

System.String DirectoryName {get;} System.Boolean Exists {get;} System.String Extension {get;} System.String FullName {get;} System.Boolean IsReadOnly {get;set;} System.DateTime LastAccessTime {get;set;} System.DateTime LastAccessTimeUtc {get;set System.DateTime LastWriteTime {get;set;} System.DateTime LastWriteTimeUtc {get;set; System.Int64 Length {get;} System.String Name {get;}

LastWriteTime Property LastWriteTimeUtc Property } Length Name Property Property

After you find the properties, you can use them in your Windows PowerShell commands. Property Values Although every object of a specific type has the same properties, the values of those properties describe the particular object. For example, every FileInfo object has a CreationTime property, but the value of that property differs for each file. The most common way to get the values of the properties of an object is to use the dot method. Type a reference to the object, such as a variable that contains the object, or a command that gets the object. Then, type a dot (.) followed by the property name. For example, the following command displays the value of the CreationTime property of the PowerShell.exe file. The Get-ChildItem command returns a FileInfo object that represents the PowerShell.exe file. The command is enclosed in parentheses to make sure that it is executed before any properties are accessed. The Get-ChildItem command is followed by a dot and the name of the CreationTime property, as follows: C:\PS> (Get-ChildItem $pshome\powershell.exe).creationtime Tuesday, March 18, 2008 12:07:52 AM You can also save an object in a variable and then get its properties by using the dot method, as shown in the following example: C:\PS> $a = Get-ChildItem $pshome\powershell.exe C:\PS> $a.CreationTime Tuesday, March 18, 2008 12:07:52 AM You can also use the Select-Object and Format-List cmdlets to display the property values of an object. Select-Object and Format-List each have a Property parameter. You can use the Property parameter to specify one or more properties and their values. Or, you can use the wildcard character (*) to represent all the properties. For example, the following command displays the values of all the properties of the PowerShell.exe file.

C:\PS> Get-ChildItem $pshome\powershell.exe | Format-List -property * PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Windows\sy stem32\WindowsPowerShell\v1.0\powershell.exe PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\Windows\sy stem32\WindowsPowerShell\v1.0 PSChildName : powershell.exe PSDrive : C PSProvider : Microsoft.PowerShell.Core\FileSystem PSIsContainer : False VersionInfo : File: C:\Windows\system32\WindowsPowerS hell\v1.0\powershell.exe InternalName: POWERSHELL OriginalFilename: PowerShell.EXE.MUI File Version: 6.1.6570.1 (fbl_srv_powershell(n igels).070711-0102) FileDescription: PowerShell.EXE Product: Microsoft Windows Operating System ProductVersion: 6.1.6570.1 Debug: False Patched: False PreRelease: False PrivateBuild: True SpecialBuild: False Language: English (United States) BaseName Mode Name Length DirectoryName Directory IsReadOnly Exists FullName ll.exe Extension CreationTime CreationTimeUtc LastAccessTime LastAccessTimeUtc LastWriteTime LastWriteTimeUtc Attributes SEE ALSO about_Objects Get-Member Select-Object Format-List : : : : : : : : .exe 3/18/2008 3/18/2008 3/19/2008 3/19/2008 3/18/2008 3/18/2008 Archive 12:07:52 AM 7:07:52 AM 8:13:58 AM 3:13:58 PM 12:07:52 AM 7:07:52 AM : : : : : : : : : powershell -a--powershell.exe 160256 C:\Windows\system32\WindowsPowerShell\v1.0 C:\Windows\system32\WindowsPowerShell\v1.0 False True C:\Windows\system32\WindowsPowerShell\v1.0\powershe

Das könnte Ihnen auch gefallen