#Version du 30 mars 2012 clear-host #Definition de 2 variables globales $global:MyVar01 = "" $global:MyVar02 = "" Function ParseCommand($oArgs){ #Parses the command line and fills the script variables #with the appropriate values. # $test = "-n,test" # $oArgs = $test.split(",") $ArgCount = 0 if (!$oArgs.length -gt 0){ write-host "No arguments specified." } While ($ArgCount -lt $oArgs.length){ switch ($oArgs[$ArgCount].ToLower()){ "-n"{ $global:MyVar01 = $oArgs[($ArgCount+1)] $ArgCount = ($ArgCount + 2) write-host "-n : $MyVar01" } "-p"{ $global:MyVar02 = $oArgs[($ArgCount+1)] $ArgCount = ($ArgCount + 2) write-host "-p : $MyVar02" } default{ write-host "Invalid command." # Help exit } } } } #Parse commands ParseCommand($args) $VIserver = $MyVar01 $VMName = $MyVar02 #$SnapshotName write-host "Le 1 : $VIserver" write-host "Le 2 : $VMName"