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*;$DGroups=(Get-BrokerDesktopGroup|Select PublishedName).PublishedName;ForEach($DGroup in $DGroups){Get-BrokerAccessPolicyRule -DesktopGroupName $DGroup|Select -expandproperty IncludedUsers|Select-object Name|Sort-Object -Unique}

asnp Citrix*;Get-BrokerAccessPolicyRule -DesktopGroupName 'Delivery_Group_Name' |Select -expandproperty IncludedUsers|Select-Object Name|Sort-Object -Unique

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

Get-VM|Get-HardDisk|Where-Object{$_.DiskType -like “Raw*”}|Select @{N=”ESXi”;E={$_.Parent.VMhost.Name}},@{N=”VM”;E={$_.Parent}},Name,DiskType,@{N=”SCSI ID”;E={$_.ScsiCanonicalName}},Filename,CapacityGB|Export-Csv C:\VMware\RDM-list.csv -NoTypeInformation

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}}

$getcluster=Get-Cluster;ForEach($clustername in $getcluster){ write-host;write-host $clustername -ForegroundColor Yellow;$vmhosts=Get-Cluster $clustername|Get-VMHost;$Output=@();$Output1=@();$totalhostram=0;$totalvram=0;$totalratio=0;ForEach ($vmhost in $vmhosts){$ratio=$null;$hostvram=0;$vms = Get-Cluster $clustername | 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;$Output=@();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

ForEach ($clustername in Get-Cluster) { Write-Host; Write-Host $clustername -ForegroundColor Yellow; $vmhosts = Get-Cluster $clustername | Get-VMHost; $vms = Get-Cluster $clustername | Get-VM | Where-Object { $_.PowerState -eq "PoweredOn" }; $Output = @(); $Output1 = @(); $totalvcpus = 0; $totalhostthreads = 0; $totalratio = 0; ForEach ($vmhost in $vmhosts) { $vcpus = 0; $ratio = $null; $ht = $vmhost.HyperThreadingActive; if ($ht -eq "True") { $Multiple = "0.75" } else { $Multiple = "1" }; $hostthreads = $vmhost.extensiondata.hardware.cpuinfo.numcputhreads * $Multiple; $vms | Where-Object { $_.vmhost -like $vmhost } | ForEach { $vcpus += $_.numcpu }; if ($vcpus -ne "0") { $ratio = "{0:N1}" -f ($vcpus / $hostthreads) }; $cpuUsagePercent = [Math]::Round((Get-Stat -Entity $vmhost -Stat "cpu.usage.average" -Start (Get-Date).AddDays(-7) -IntervalMins 60 | Measure-Object -Property Value -Average).Average); $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; $hvalue | Add-Member -MemberType NoteProperty "CPU %" -Value $cpuUsagePercent; $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 }
$Result = @(); ForEach ($clustername in Get-Cluster) { $Output = @(); $Output1 = @(); $totalvcpus = 0; $totalhostthreads = 0; $totalratio = 0; ForEach ($vmhost in (Get-Cluster $clustername | Get-VMHost)) { $vcpus = 0; $ratio = $null; $ht = $vmhost.HyperThreadingActive; if ($ht -eq "True") { $Multiple = 0.75 } else { $Multiple = 1 }; $hostthreads = $vmhost.extensiondata.hardware.cpuinfo.numcputhreads * $Multiple; (Get-Cluster $clustername | Get-VM | Where-Object { $_.vmhost -like $vmhost }) | ForEach { $vcpus += $_.numcpu }; if ($vcpus -ne 0) { $ratio = "{0:N1}" -f ($vcpus / $hostthreads) }; $cpuUsagePercent = [Math]::Round((Get-Stat -Entity $vmhost -Stat "cpu.usage.average" -Start (Get-Date).AddDays(-7) -IntervalMins 60 | Measure-Object -Property Value -Average).Average); $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; $hvalue | Add-Member -MemberType NoteProperty "CPU %" -Value $cpuUsagePercent; $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; $Result += $Output; $Result += $Output1 }; $Result | Out-GridView

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-Datastore|Select Name,@{N="Total_GB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},@{N="Used_GB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N=”Free_GB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity - ($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace))/1GB,0)}},@{N='%_Free';E={[Math]::Round($_.FreespaceGB/$_.CapacityGB*100,0)}}|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