Module 2 of Powershell
Module 2 of Powershell
Get-Childitem:
Get the list of items available in file system/certificate store / registry.
Eg:
Get-Childitem C:\windows
Get-Childitem c:\windows –filter “*.txt”
Get-Childitem c:\windows –recuse
Where-Object:
• Used for filtering objects in the pipeline
Aliases: where, ?
• Traditional syntax uses a script block and $_
PS C:\> get-service m* | where {$_.status –eq 'running'}
• New syntax can be simpler
PS C:\> get-service m* | where status –eq 'running
Sort-Object:
• Sort objects on property value, usually numeric
Alias: sort
• Specify a comma separated list of property names
Can sort on a custom property
• Default order is ascending
Or use –Descending
Can only sort multiple properties in one direction unless you use custom properties
• Not case-sensitive by default
• Get objects with a uniquevalue for property name
• •PS C:\> get-process | sort WorkingSet –descending | select –first 10
– Remoting tabs
Alias = ft
Output may be truncated
Customize appearance
Wrap
Autosize
Format-List:
Alias=fl
Ouput less likely to be truncated
Specify property to display
Create Custom properties
Group data by property
Format-Wide:
Alias=fw
Good for simple, broad display
Output may be truncated
Specify property to display
Specify number of columns
Autosize
Group by property
PSProviders:
• Software that translates data storage to a PowerShell friendly format
• Typical hierarchical data structures
✓ FileSystem
✓ Registry
✓ Certificate Store
✓ Active Directory
✓ WSMan
✓ Environment
✓ IIS
• Additional providers may be added via Modules/Snap-Ins
• Get-PSProvider to view installed providers
• To get help Help About_Providers
Creating PSDrive:
• Use New-PSDrive
- Specify drive name
- Specify provider name
- Specify path
- Options : Credential, Persistence
• Drives not necessarily seen by Windows
• Add drive settings to your PowerShell profile script
Removing PSDrive:
• User defined drives end with session
• Use Remove-PSDrive to manually removal
• Can’t remove Windows or fixed drives
• Don’t try to remove your current drive
Working with Item/Item Property:
• Get-Item – Gets the item at specified location
• Get-ItemProperty – gets the properties of specified item
• Remove-Item – Deletes the item
• Set-Item – Change the value of item
• Clear-item – To clear content of an item
• Rename-Item/ItemProperty – Renames the Item/ItemProperty
• Copy-Item/ItemProperty – Copy Item/ItemProperty
• Move-Item/ItemProperty – Move Item/ItemProperty to different location