Juil 162014
 

La m?thode longue consiste ? se connecter sur chaque VM, et a executer ce qui suit :

First thing is to log onto the virtual machine and open up msinfo32 via the run prompt (start > run > msinfo32).
Expand ?Software Environment? and then ?System Drivers?
Within this list you?re looking for vsepflt as shown below:

La m?thode automatis?e :
Pensez ? d?sactiver votre proxy de Internet Explorer (oui, je sais, c’est ?trange, et je n’ai ni le temps, ni l’envie de rentrer dans les d?tails)

$credentials=Get-Credential
$VMStatus=Get-VM | Where-Object { $_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "WinDows" } | ForEach-Object {
$obj=New-Object PSObject
$obj | add-Member Noteproperty -name Name -value $_.name
#? $obj | add-Member Noteproperty -name vShield -value? (Invoke-VMScript -VM $_.name -ScriptType Bat -ScriptText 'driverquery | find /i "vsepflt"' -GuestCredential $credentials -ErrorAction Continue | Select-Object -ExpandProperty ScriptOutput)
$obj | add-Member Noteproperty -name ToolsVersion -value $_.ToolsVersion
$obj | add-Member Noteproperty -name ToolsVersionStatus -value $_.ToolsVersionStatus
$obj | add-Member Noteproperty -name SnapShotCount -value ($_ | Get-Snapshot | Measure-Object | select -ExpandProperty Count )
$obj | add-Member Noteproperty -name SnapShotInfo -value ($_ | Get-Snapshot | select VM,Created, SizeGB, IsCurrent, Name |Out-String )
$obj
}
$VMStatus | out-gridview

Si vous avez le m?me bug que moi, cad, que le re-enregistrement des adresses IP dans le DNS echoue et que le DNS se retrouve vide : http://support.microsoft.com/default.aspx?scid=kb;EN-US;2520155
Pour mettre a jour de maniere pseudo-automatis?e le parc

$credentials=Get-Credential

Get-VM | Where-Object { $_.PowerState -eq « PoweredOn » -and $_.Guest.OSFullName -match « WinDows » -and ($_ | get-snapshot | Measure-Object | select -ExpandProperty Count ) -eq 0 } | foreach {
Get-VM -name svMGTTST01 | foreach {
# ping to check if VM is pinguable
if (Test-Connection $_.name -ErrorAction SilentlyContinue ) { write-host « Ping to $_ : OK » -foregroundcolor green } else { write-host « Ping to $_ : Failed » -foregroundcolor red }
# Take snapshot
New-Snapshot -vm $_.name -Name « Avant VMWare Tools et vShield » -Description « VM avant execution du script automatique » -Memory:$true -Quiesce:$true -Confirm:$false
# Update tools
$_ | Get-View | foreach { $_.Guest.ToolsVersion }
$_ | Mount-Tools
# Copy BAT file
$DestinationFIle= »\\ »+(($_|get-view).Guest.HostName)+ »\c$\UpdateVMwareToolsManually.cmd »
Copy-Item -Path ‘C:\Users\Moi\Desktop\Scripts\VMwareTOols\UpdateVMwareToolsManually.cmd’ -Destination $DestinationFile
Invoke-VMScript -VM $_.name -ScriptType Bat -ScriptText ‘C:\UpdateVMwareToolsManually.cmd’ -GuestCredential $credentials | Select-Object ScriptOutput
Remove-Item $DestinationFile

# unmount
$_ | Wait-Tools

if ( (get-vm svMGTTST01 | Get-CDDrive ).isoPath.Equals(« [] /usr/lib/vmware/isoimages/windows.iso ») -eq $true ) { write-host « CD still mounted. Problem detected » -foregroundcolor red }

# Not necessary. Correct update unmount CDROM.
# $_ | Dismount-Tools

$_ | Get-View | foreach { $_.Guest.ToolsVersion }

# ping to check if VM is still pinguable
if (Test-Connection $_.name -ErrorAction SilentlyContinue ) { write-host « Ping to $_ : OK » -foregroundcolor green } else { write-host « Ping to $_ : Failed » -foregroundcolor red }

# delete snapshot
$_ | Get-Snapshot -Name « Avant VMWare Tools et vShield » | Remove-Snapshot -Confirm:$true
}

Et le script ? envoyer sur chaque VM:

SETLOCAL ENABLEDELAYEDEXPANSION

REM Usage : perform VMWareTools Assisted update and DNS registration
REM http://support.microsoft.com/default.aspx?scid=kb;EN-US;2520155
(
date /t
time /t

set DriveLetter=unknown
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do? ( if exist %%a:\VMwareToolsUpgrader.exe if exist %%a:\certified.txt set DriveLetter=%%a)
echo DriveLetter : !DriveLetter!

REM check current version of vShield
driverquery | find /i « vsepflt »

!DriveLetter!:\Setup.exe /S /v « /qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs »
ipconfig /registerdns

REM check new version of vShield
driverquery | find /i « vsepflt »

date /t
time /t
) >> C:\UpdateVMwareToolsManually.log 2>&1

Fév 282014
 

Fonction ? garder dans un coin :

Function Get-RDPSession {
    [cmdletbinding(DefaultParameterSetName = 'session',ConfirmImpact = 'low')]
    Param(
        [Parameter(Mandatory = $True,Position = 0,ValueFromPipeline = $True)]  [string[]]$name)             
Begin {$report = @()}
Process { 
    foreach ($computer in $name) {
        write-host Checking $computer. 
        if ( Test-Connection svc -ErrorAction SilentlyContinue -Count 1    ) {
            $sessions = query session /server:$computer
            1..($sessions.count -1) | % {
                $temp = "" | Select Computer,SessionName, Username, Id, State, Type, Device
                $temp.Computer = $computer
                $temp.SessionName = $sessions[$_].Substring(1,18).Trim()
                $temp.Username = $sessions[$_].Substring(19,20).Trim()
                $temp.Id = $sessions[$_].Substring(39,9).Trim()
                $temp.State = $sessions[$_].Substring(48,8).Trim()
                $temp.Type = $sessions[$_].Substring(56,12).Trim()
                $temp.Device = $sessions[$_].Substring(68).Trim()
                $report += $temp
            } 
        }
    }
}
End {$report}
}

Exemple d’utilisation :

# Get-RDPSession -name svctxpd01 -ErrorAction silentlycontinue

Dans le cadre d’un AD, et en s?lectionnant que certains serveurs :

import-module activedirectory
Get-RDPSession -name (get-adcomputer -Filter 'Name -like "VM_DESK*"' | select -ExpandProperty name ) | Out-GridView

Tout l’AD :

Get-RDPSession -name (get-adcomputer -Filter * | select -ExpandProperty name ) | Out-GridView

Un autre AD que l’AD principal:

Get-RDPSession -name (Get-ADComputer -Server DC_AUTRE_DOMAINE -filter 'name -like "*"' | select -ExpandProperty name ) | Out-GridView

Bref… que du bonheur !!!

Jan 272014
 

Se connecter ? tous les vCenters (si on en a plusieurs)

Connect-VIServer VC.dev
Connect-VIServer VC.acc

Sortir la liste de toutes les HBA (Fibre Channel)

Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device | Out-GridView

Sortir la liste de tous les identifiants BIOS (UUID) de chaque serveur

(Get-VMHost |? get-view) | select name,@{label='UUID';expression={$_.hardware.systeminfo.uuid}} | out-gridview

Sortir la liste des HOSTS, le num?ro de s?rie du chassis, l’IP de leur vCenter et l’UUID.

(Get-VMHost | get-view) | select name,
 @{label='Chassis Serial Number';expression={($_).summary.Hardware.OtherIdentifyingInfo[-1].IdentifierValue}},
@{label='vCenter IP';expression={$_.summary.ManagementServerIp}},
@{label='UUID';expression={$_.summary.hardware.uuid}} | out-gridview

xx

.summary.ManagementServerIp

 

Jan 272014
 

Cr?er le vSwitch (et conserver l’information pour y ajouter les port Group

$VirtualSwitch = New-VirtualSwitch -VMHost VESX01 -name vSwitch1 -NumPorts 256 -Nic vmnic1,vmnic4

Ou, r?cup?rer le vSwitch existant:

$VirtualSwitch=(Get-VMHostNetwork -VMHost VESX01).VirtualSwitch[1]

Cr?er les portGroup avec les vLans

New-VirtualPortGroup -Name "DMZ" -VirtualSwitch $virtualSwitch -VLanId 13
New-VirtualPortGroup -Name "FrontEnd WEB" -VirtualSwitch $virtualSwitch -VLanId 14

Et voil?…

Nov 102013
 

J’ai des VMs sur un host, et je veux les envoyer sur un autre host, mais en prenant bien mon temps, car la ligne est lente et les serveurs peu puissant.

Voici comment j’ai fait :

$VMs=Get-VM -Datastore NomDuDatastore| where { $_.vmhost.name -eq "EsxSource" }
 foreach ($VM in $VMs) {
 Write-Host "------------- Moving $VM -------------" -foreground "Yellow"
 $VM | move-vm -Destination (get-vmhost "EsxDestination")
 Write-Host "------------- Moved? $VM --------------" -foreground "Green"
 Write-Host "."
 Write-Host "."
 sleep 60
 }

Concretement: Toutes les VMs qui se trouvent sur un ESX « EsxSource » ET sur le datastore « NomDuDatastore » sont envoy?es vers « EsxDestination« .

Une VM ? la fois, et en attendant 1 minute apr?s chaque transfert.

Nov 102013
 

Ouvrez une console PowerShell et indiquez ce code :

Set-Alias ngen @(
dir (join-path ${env:\windir} "Microsoft.NET\Framework") ngen.exe -recurse |
sort -descending lastwritetime
)[0].fullName
[appdomain]::currentdomain.getassemblies() | %{ngen $_.location}

Et PAF, ca fait des chocapics, ca fonctionne !