Skip to content

Instantly share code, notes, and snippets.

@vexx32
Last active December 4, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/a55d5f778cd4e115ed18d0e0a0958efd to your computer and use it in GitHub Desktop.
Save vexx32/a55d5f778cd4e115ed18d0e0a0958efd to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param(
[Parameter(Mandatory, HelpMessage="Enter one or more VM names separated by commas. Value should not be null or empty")]
[ArgumentCompleter(
{
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
if ($WordToComplete) {
@((Get-VM).Name) -match "^$WordToComplete"
}
else {
(Get-VM).Name
}
}
)]
[ValidateScript(
{
foreach ($Name in $_) {
if (-not (Get-VM $Name -ErrorAction SilentlyContinue)) {
throw "Please enter a valid VM Name."
}
}
}
)]
[String[]]
$servername
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment