Wednesday, October 13, 2010

Removing aliases from PowerShell to aid in learning and script stability

When using PowerShell 2.0, it is easy to rely on aliases for functionality.  The excellent Windows PowerShell 2.0 Best Practices book suggests removing all the aliases to ensure you don’t use them accidentally.  Unfortunately, the code provided will only work if you have changed your location to the alias: location before running it.  The following code should work without the need to use set-location first:

foreach($alias in (get-alias | where-object {$_.options -notmatch 'readonly'})){remove-item alias:\$alias}

No comments:

Post a Comment