Use scripts to verify input parameters
Using scripts to validate input
Http://powershell.com/cs/blogs/tips/archive/2010/08/30/using-scripts-to-validate-input.aspx
PassValidatescript.
Function copy-oldfiles {
Param (
$ Days = 30,
[Parameter (valuefrompipeline = $ true)]
[System. Io. fileinfo]
[Validatescript ({(New-timespan $ _. lastwritetime). Days-GT $ days})]
$ Fileobject
)
Process {
"Archiving file {0} (age {1})..."-F $ fileobject. fullname, (new-timespan $ _. lastwritetime). Days
}
}
I personally feel that it is easier to understand and implement in the method body.
View Object Inheritance relationships
View Object Inheritance
Http://powershell.com/cs/blogs/tips/archive/2010/08/31/view-object-inheritance.aspx
APstypenamesThe hidden attribute of can display the inheritance connection of an object.
(Get-wmiobject win32_bios). pstypenames
AndGetType ()This property is valid for all objects, includingComObject. The most common method is to obtain the first element of the inheritance chain:
(Get-wmiobject win32_bios). pstypenames [0]
Version Comparison
Comparing versions
Http://powershell.com/cs/blogs/tips/archive/2010/09/01/comparing-versions.aspx
When comparing the versions saved by two string types,PowershellIt uses characters and numbers.Algorithm(?) For example:
'A'-GT 'B'
False
The following error is returned:
'3. 4.22.12 '-GT '22. 1.4.34'
True
You need to setStringType conversionSystem. VersionType. In fact, you only need to convert the type on the left, because the right side will also be converted as follows:
[System. Version] '3. 4.22.12 '-GT '22. 1.4.34'
False
Type accelerator (?)
Type accelerators
Http://powershell.com/cs/blogs/tips/archive/2010/09/02/type-accelerators.aspx
PowershellFor some. NetType provides some shortcuts, suchWMI,ADSIOrInt, You can useFullnameAttribute to get the full name of a type name:
[WMI]. fullname
System. Management. managementobject
Direct AccessWMIInstance
Accessing WMI instances directly
Http://powershell.com/cs/blogs/tips/archive/2010/09/03/accessing-wmi-instances-directly.aspx
If you knowWMIInstance path, you can directlyWMIConverts a path string toWMIObject.
[WMI] 'win32 _ service. Name = "w32time "'
[WMI] 'win32 _ logicaldisk = "C :"'
You can also specify a completeWMIPath, including the machine Name:
[WMI] '\ server5 \ Root \ cimv2: win32_service.name = "w32time "'
FromPowershell.com
2010JanuaryFrom the 16 th to the 20 thPowertip of the day