This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.Dynamic ValidateSet values using classes | |
| Class SoundNames : System.Management.Automation.IValidateSetValuesGenerator { | |
| [string[]] GetValidValues() { | |
| $SoundPaths = '/System/Library/Sounds/', | |
| '/Library/Sounds', | |
| '~/Library/Sounds' | |
| $SoundNames = ForEach ($SoundPath in $SoundPaths) { | |
| If (Test-Path $SoundPath) { | |
| (Get-ChildItem $SoundPath).BaseName | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Import-xml | |
| using namespace system.xml.linq | |
| class script { | |
| [scriptblock]$scriptblock | |
| [string]$name | |
| #1.add hidden path | |
| hidden [string]$path = "$PSScriptRoot\xml\script.xml" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 解释: | |
| 在代码中可能遇见一种情况需要向外一层层的解剖一个object,但是我们只能从根据内部推出外部. | |
| 实例: | |
| 我们需要通过一个xml表构建一个psobject | |
| 此时我们要构建这个psobject,我们试从xml一层层地剖析 | |
| ``` | |
| ([pscustomobject]@{roadcoordinate=@{ | |
| > roadcoordinte1=@{x=1 | |
| > y=1 | |
| > z=1 |
NewerOlder