One|Liner

How to easy enhance your Administration

Le OneLiner est un script compressé en une seule ligne !
Ceci lui permettant de se lancer via un simple copier/coller dans une fenêtre VMware PowerCLI ou Microsoft PowerShell.

Il est devenu au fil du temps une évidence pour les Administrateurs :
– Simple à utiliser
– Facilement compréhensible
– Challenge de toujours faire plus court

Citrix

asnp Citrix*
Get-BrokerDesktop|Select {$_.MachineName}, {$_.AssociatedUserFullNames}, {$_.AssociatedUserNames}|ft -AutoSize

asnp Citrix*
New-BrokerRebootScheduleV2 -Name "Wednesday Reboot for SSL" -DesktopGroupName "Nom_du_Delivery_Group" -Day Wednesday -Frequency Weekly -StartTime "2:00" -RebootDuration 120 -RestrictToTag Nom_du_Tag -WarningDuration 30 -WarningRepeatInterval 10 -WarningMessage "This machine will restart in %m% minutes. Please save your work." -WarningTitle "Warning: Reboot Pending" -Enabled $true

VMware

foreach($snap in Get-VM|Get-Snapshot){$snapevent=Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1|Where-Object{$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'};if ($snapevent -ne $null){Write-Host(""+ $snap.VM + " - Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + " by " + $snapevent.UserName +".")}else {Write-Host(""+ $snap.VM + " - Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + ". This event is not in vCenter events database")}}

Get-VM|Select-Object Name,@{n="VMDKsGB";e={[math]::round((Get-HardDisk -VM $_|Measure-Object -Sum CapacityGB).Sum)}},@{n="DSName";e={(Get-Datastore -VM $_)}}|sort VMDKsGB|ft -AutoSize

Get-VM|ForEach{write-host $_ -ForegroundColor Yellow;$_.Guest.Nics.IPAddress;write-host}

Get-VM|ForEach{write-host $_ -ForegroundColor Yellow;Get-VM $_|Get-NetworkAdapter|select -ExpandProperty NetworkName;Get-VM $_|Get-NetworkAdapter|select -ExpandProperty MacAddress;write-host}

Get-Snapshot *|Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'};Write-Host "" $snap.VM ": Snapshot" $snap "created on" $snap.Created.DateTime "by" $snapevent.UserName ""

Get-Snapshot *|Select-Object -Property VM,Name,Created,@{n="SizeGB";e={[math]::round($_.SizeGB)}},Description|Sort-Object -Property SizeGB -Descending|ft -AutoSize

Get-View -ViewType Datastore -Property Name,Browser -Filter @{"Name" = "^DS_Name$"}|%{(Get-View $_.Browser).SearchDatastoreSubFolders($("[" + $_.Name + "]"),(New-Object VMware.Vim.HostDatastoreBrowserSearchSpec -Property @{matchPattern=("*.vmx")}))}|%{(Get-View -ViewType Folder -Property Name -Filter @{"Name" = "^vm"}).GetType().GetMethod("RegisterVM_Task").Invoke($(Get-View -ViewType Folder -Property Name -Filter @{"Name" = "^vm"}),@($($_.FolderPath + "/" + $_.File.Path),$null,$false,(Get-View -ViewType ResourcePool -Property Name -Filter @{"Name" = "Resources"}).MoRef,$null))}

Get-VM|Where-Object -FilterScript{$_.Guest.Nics.IPAddress -contains "1.2.3.4"}

Get-VM|Get-VMResourceConfiguration|Where-Object{$_.MemLimitMB -ne ‘-1’}|Set-VMResourceConfiguration -MemLimitMB $Null

$guestConfig=New-Object VMware.Vim.VirtualMachineConfigSpec;$guestConfig.memoryReservationLockedToMax=$False;(Get-VM).ExtensionData.ReconfigVM_task($guestConfig);Get-VM|Get-VMResourceConfiguration|Set-VMResourceConfiguration -MemReservationMB 0

$guestConfig=New-Object VMware.Vim.VirtualMachineConfigSpec;$guestConfig.memoryReservationLockedToMax=$True;(Get-VM).ExtensionData.ReconfigVM_task($guestConfig)

Get-Datastore "Source_DS"|Get-VM|Move-VM -DiskStorageFormat "EagerZeroedThick" -Datastore "Destination_DS" –RunAsync
Get-Datastore "Source_DS"|Get-VM|Select Name,@{N="Datastore";E={$_|Get-Datastore}}

param($vmhosts="*");$Cluster_Name="Nom_du_Cluster";$vmhosts=Get-Cluster $Cluster_Name|Get-VMHost;[email protected]();[email protected]();$totalhostram=0;$totalvram=0;$totalratio=0;ForEach ($vmhost in $vmhosts){$ratio=$null;$hostvram=0;$vms = Get-Cluster $Cluster_Name | Get-VMHost $vmhost | Get-VM | where {$_.PowerState -eq "PoweredOn"};ForEach ($vm in $vms){$vram=0;$vram = $vm.MemoryGB;$hostvram += $vram};$totalvram += $hostvram;$hostram="{0:N0}" -f ($vmhost.memorytotalGB);$ratio = "{0:N1}" -f ($hostvram/$hostram);$hvalue= New-Object psobject;$hvalue| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name;$hvalue| Add-Member -MemberType Noteproperty "hRAM" -Value $hostram;$hvalue| Add-Member -MemberType Noteproperty "vRAM" -Value $hostvram;$hvalue| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio;$Output+=$hvalue;$totalhostram += $hostram};$totalratio = "{0:N1}" -f ($totalvram/$totalhostram);$cvalue= New-Object psobject;$cvalue| Add-Member -MemberType Noteproperty "Hostname" -value "Cluster";$cvalue| Add-Member -MemberType Noteproperty "hRAM" -Value $totalhostram;$cvalue| Add-Member -MemberType Noteproperty "vRam" -Value $totalvram;$cvalue| Add-Member -MemberType Noteproperty "Ratio" -Value $totalratio;$Output1+=$cvalue;$Output|ft -autosize;$Output1|ft -autosize

$Cluster_Name="Nom_du_Cluster";$vms=Get-Cluster $Cluster_Name|Get-VM;[email protected]();foreach($vm in $vms){$value=Get-NetworkAdapter -VM $vm;$hvalue=New-Object psobject;$hvalue|Add-Member -MemberType Noteproperty "VM Name" -value $vm.Name;$hvalue| Add-Member -MemberType Noteproperty "vNIC" -Value $value.Type;$Output+=$hvalue};$Output|Format-Table -AutoSize

param($vmhosts="*");$Cluster_Name="Nom_du_Cluster";$vmhosts=Get-Cluster $Cluster_Name|Get-VMHost;$vms=Get-Cluster $Cluster_Name|Get-VM|where {$_.PowerState -eq "PoweredOn"};[email protected]();[email protected]();$totalvcpus=0;$totalhostthreads=0;$totalratio=0;ForEach($vmhost in $vmhosts){$vcpus=0;$ratio=$null;$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.numcputhreads*0.75;$vms|Where-Object{$_.vmhost -like $vmhost}|ForEach{$vcpus+=$_.numcpu};if($vcpus -ne "0"){$ratio= "{0:N1}" -f ($vcpus/$hostthreads)};$hvalue=New-Object psobject;$hvalue|Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name;$hvalue|Add-Member -MemberType Noteproperty "pCPU" -Value $hostthreads;$hvalue|Add-Member -MemberType Noteproperty "vCPU" -Value $vcpus;$hvalue|Add-Member -MemberType Noteproperty "Ratio" -Value $ratio;$Output+=$hvalue;$totalhostthreads += $hostthreads;$totalvcpus += $vcpus;$totalratio="{0:N1}" –f ($totalvcpus/$totalhostthreads)};$cvalue=New-Object psobject;$cvalue|Add-Member -MemberType Noteproperty "Hostname" -value "Cluster";$cvalue|Add-Member -MemberType Noteproperty "pCPU" -Value $totalhostthreads;$cvalue|Add-Member -MemberType Noteproperty "vCPUs" -Value $totalvcpus;$cvalue|Add-Member -MemberType Noteproperty "Ratio" -Value $totalratio;$Output1 += $cvalue;$Output|ft -autosize;$Output1|ft -autosize

param($vmhosts="*");$Cluster_Name="Nom_du_Cluster";$vmhosts=Get-Cluster $Cluster_Name|Get-VMHost;$vms=Get-Cluster $Cluster_Name|Get-VM|where {$_.PowerState -eq "PoweredOn"};[email protected]();[email protected]();$totalvcpus=0;$totalhostthreads=0;$totalratio=0;ForEach($vmhost in $vmhosts){$vcpus=0;$ratio=$null;$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.numcputhreads;$vms|Where-Object{$_.vmhost -like $vmhost}|ForEach{$vcpus+=$_.numcpu};if($vcpus -ne "0"){$ratio= "{0:N1}" -f ($vcpus/$hostthreads)};$hvalue=New-Object psobject;$hvalue|Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name;$hvalue|Add-Member -MemberType Noteproperty "pCPU" -Value $hostthreads;$hvalue|Add-Member -MemberType Noteproperty "vCPU" -Value $vcpus;$hvalue|Add-Member -MemberType Noteproperty "Ratio" -Value $ratio;$Output+=$hvalue;$totalhostthreads += $hostthreads;$totalvcpus += $vcpus;$totalratio="{0:N1}" –f ($totalvcpus/$totalhostthreads)};$cvalue=New-Object psobject;$cvalue|Add-Member -MemberType Noteproperty "Hostname" -value "Cluster";$cvalue|Add-Member -MemberType Noteproperty "pCPU" -Value $totalhostthreads;$cvalue|Add-Member -MemberType Noteproperty "vCPUs" -Value $totalvcpus;$cvalue|Add-Member -MemberType Noteproperty "Ratio" -Value $totalratio;$Output1 += $cvalue;$Output|ft -autosize;$Output1|ft -autosize

Get-VMHost|Sort Name|Get-View|Select Name,@{N=“HW Type“;E={$_.Hardware.SystemInfo.Vendor+ “ “ + $_.Hardware.SystemInfo.Model}},@{N=“Socket(s)“;E={$_.Hardware.CpuInfo.NumCpuPackages}},@{N=“Core(s)“;E={[math]::round($_.Hardware.CpuInfo.NumCpuCores / $_.Hardware.CpuInfo.NumCpuPackages)}},@{N=“Logical CPUs“;E={[math]::round($_.Hardware.CpuInfo.NumCpuCores)}},@{N=“CPU“;E={"" + [math]::round($_.Hardware.CpuInfo.Hz / 1000000000, 2) + " Ghz"}},@{N=“RAM“;E={“” + [math]::round($_.Hardware.MemorySize / 1GB, 0) + “ GB“}} | Export-Csv C:\ESXi_HW.csv

Get-VM|Get-View|Select-Object @{N=”VM Name”;E={$_.Name}},@{Name=”Status Tools”;E={$_.Guest.ToolsStatus}}|Export-CSV C:\VMwareToolsStatus.csv

Get-VMHost|Foreach-Object{$ClusterName=$_.Parent.Name; $HostName = $_;Get-VirtualPortGroup $_|Select-Object @{N="Cluster";E={$ClusterName}},@{N="Host";E={$HostName}},Name,VLanId}|Export-CSV C:\PortGroup_List.csv

Get-VM|ForEach-Object{Get-View $_.ID}|ForEach-Object{if($_.Config.Version -like "vmx-11"){Write-Host $_.Name -ForegroundColor Yellow}}

Get-VM|ForEach{$View=Get-View $_;if($View.config.hardware.Device.Backing.ThinProvisioned -eq $true){Get-Cluster -VM $_|Select Name;write-host $_ -ForegroundColor Yellow;write-host""}}

Get-Content DS_List.txt|Foreach{Get-Datastore -Name $_|Select Name,@{N=”Total_GB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},@{N="Provisioned"; E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},@{N=”Real_Free”;E={[Math]::Round(($_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N="Free"; E={([Math]::Round($_.ExtensionData.Summary.Capacity/1GB,0)) - ([Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0))}},@{N='%_Free';E={[Math]::Round("{0:N2}" -f (($_.ExtensionData.Summary.FreeSpace/$_.ExtensionData.Summary.Capacity)))}}}|Sort-Object -Property %_Free|Format-Table -AutoSize

Get-Cluster Nom_du_Cluster|Get-VMHost|%{(Write-Host $_ " " -ForegroundColor Green),(Get-EsxCli -VMHost $_).system.version.get()|select Update,Version}|fl -autosize

Get-Cluster Nom_du_Cluster|Get-VMHost|Foreach{Start-VMHostService -HostService ($_|Get-VMHostService|Where {$_.Key -eq "TSM-SSH"}) -Confirm:$false}

Get-Cluster Nom_du_Cluster|Get-VMHost|Foreach{Stop-VMHostService -HostService ($_|Get-VMHostService|Where {$_.Key -eq "TSM-SSH"}) -Confirm:$false}

Get-Cluster Nom_du_Cluster|Get-VMHost|Get-VM|select @{N="DnsName"; E={$_.ExtensionData.Guest.Hostname}}|Export-CSV C:\FQDN_VMs.csv

Get-VMHost|Foreach{(Write-Host -NoNewLine $_ -ForegroundColor Green),($_|Get-AdvancedSetting -Name Vpx.Vpxa.config.vpxa.hostIp|Format-Wide -Property Value)}

Get-Cluster Nom_du_Cluster|Get-VMHost|Get-VirtualSwitch -Name vSwitch1|New-VirtualPortGroup -Name Nom_du_PG -VLanId Num_du_VLAN

Get-Cluster Nom_du_Cluster|Get-VMHost|Get-VirtualSwitch -Name vSwitch1|Get-VirtualPortGroup -Name Nom_du_PG|Remove-VirtualPortGroup -Confirm:$false