Clear-Host $VIserver = "NomvCenter" $VILogin = "domaine\loginvcenter" $VIMotdepasse = "Motdepasse" #Definition des variables globales $global:varNomVM = "" function main() { asnp vmware* #Import modules VMWares $ErrorActionPreference = "Continue" if ($verbose) {$VerbosePreference = "Continue"} if ($debug) {$DebugPreference = "Continue"} $DebugPreference = "SilentlyContinue" CheckVIToolKit Connect-VIServer -Server $VIserver -User $VILogin -Password $VIMotdepasse Write-Host "Traitement de $varNomVM" $UneVM = Get-VM -Name $varNomVM Write-Host $UneVM.PowerState #Juste pour afficher si la VM est allumée ou non $Error.Clear() Write-Host "$varNomVM : Effacement des Snapshots" Get-Snapshot $varNomVM | Remove-Snapshot -confirm:$false } function CheckVIToolKit() { ## Before we do anything we must check to see if the user has the VI toolkit installed. ## If user does not then we prompt the user and exit. $Error.Clear() Get-PSSnapin vmware* if($Error.Count -ne 0) { Clear-Host Write-Host "`n`n`t`t ERROR - To run this script, the VI Toolkit must be installed and registered with Powershell. If the VI Tollkit is installed," -foregroundcolor red -backgroundColor yellow Write-Host "`t`t go to the Settings menu in Powershell Plus and click on Manage Snapins." -foregroundcolor red -backgroundColor yellow # Read-Host "`n`n`t Press to continue." break } }## EOF: CheckVIToolKit() 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()){ "-v"{ $global:varNomVM = $oArgs[($ArgCount+1)] $ArgCount = ($ArgCount + 2) write-host "-v : $varNomVM" break } default{ write-host "Invalid command." # Help exit } } } } #Parse commands ParseCommand($args) ## Run Main main