I get sick of repeating code. In that spirit this function gives me one line to create a new file (or folder) instead of four (or more) quickly:
functionCreate-FSOIfNotExists
{
param(
[ValidateNotNullOrEmpty()]
$path,
[ValidateSet(Directory,File)]
$itemtype
)
if(-not(Test-Path-Path$path))
{
New-Item-Path$path-ItemType$itemtype |
Out-Null;
}
}
All sorts of Verbose output could (probably should) be added to this to make it chattier, but, I just needed a quick utility function and this does the trick.
0 comments:
Post a Comment