Powertip of the day from powershell.com last week Summary (7)

Source: Internet
Author: User

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.