Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

[PS1] Create Commands with functions and alias

Publié le par damcuvelier

si chemin contient ":" alors fonction suivante et que le chemin n'existe pas, on le crée et on attribut ce chemin à la viariable:

If path contains ":" then next function and the path does not exist, we create it and we attribute this path to the variable:

function modulopath{param([Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true)][AllowEmptyString()][string]$a);if($a -match ‘:’){$path = [string]($a.split(":")[0]) + ":" + [string]($a.split(":")[1]);if(!(Test-Path $path)){New-Item -ItemType Directory -Force -Path $path | out-null;$a = $path;return $a}}}
Set-Alias -force usefolder modulopath -Option AllScope -ErrorAction SilentlyContinue

$toto = usefolder "C:\toto:"
write-host $toto => C:\toto


(

ça semble sans intérêt pour l'instant, mais ce petit module va s'avérer très utile pour le CompatibilityTool en cours de réflexion

It seems uninteresting at the moment, but this small module will prove very useful for the CompatibilityTool being considered

)

Commenter cet article