Skip to content

Instantly share code, notes, and snippets.

View CN-CODEGOD's full-sized avatar
😏
share my thought

CN-CODEGOD

😏
share my thought
View GitHub Profile
@CN-CODEGOD
CN-CODEGOD / gist:0e7a583ebe22dd498060c04612345897
Last active November 22, 2024 20:37
使用powershell 添加autocompletion
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
}
@CN-CODEGOD
CN-CODEGOD / gist:dd415e0ab67f5f900982bfa227b11c47
Last active December 17, 2024 17:13
HOW to write the save method
Import-xml
using namespace system.xml.linq
class script {
[scriptblock]$scriptblock
[string]$name
#1.add hidden path
hidden [string]$path = "$PSScriptRoot\xml\script.xml"
@CN-CODEGOD
CN-CODEGOD / gist:0106b8007928cde15985e4d12687c6a6
Created September 12, 2024 09:48
如何逆推多层级的结构代码
解释:
在代码中可能遇见一种情况需要向外一层层的解剖一个object,但是我们只能从根据内部推出外部.
实例:
我们需要通过一个xml表构建一个psobject
此时我们要构建这个psobject,我们试从xml一层层地剖析
```
([pscustomobject]@{roadcoordinate=@{
> roadcoordinte1=@{x=1
> y=1
> z=1