Category: PowerShell

Powercli: Get VM’s With CPU and Memory Reservation

Powercli: Get VM’s With CPU and Memory Reservation

Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -or $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation -ne "0"}
Advertisements
PS: Windows Update

PS: Windows Update

Needing to run Windows Updates on your machine from PowerShell this is the module for you.

https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

Download and extract the folder a place it in the following directory

%WINDIR%\System32\WindowsPowerShell\v1.0\Modules

Import the module into your PowerShell session

Import-Module PSWindowsUpdate

To download and install windows updates run the following

Get-WUInstall

Screenshot of Module In action

powershell-windows-update-screenshot

PowerCLI: Rename Windows Guest OS Hostname

PowerCLI: Rename Windows Guest OS Hostname

Okay, today I had run a script but I had not taken into account the character limit of the Windows hostname. The Result was I had 14 VM’s that are all running with the same hostname and I was not prepared to go into every single VM and change the hostname manually.

So the solution, I had been fishing around the internet for a quick solution to this problem and the solution was to use PowerCli with the Invoke-VMscript command which turns out to be pretty powerful so below is an example of using Invoke-VMscript to change the Windows Hostname

Invoke-VMScript -VM VM-Windows-01 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-01 -Restart' -GuestUser Administrator -GuestPassword ChangeMe
Invoke-VMScript -VM VM-Windows-02 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-02 -Restart' -GuestUser Administrator -GuestPassword ChangeMe
Invoke-VMScript -VM VM-Windows-03 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-03 -Restart' -GuestUser Administrator -GuestPassword ChangeMe

 

PowerCLI: SAN Usage Report

PowerCLI: SAN Usage Report

 

Okay, today I have been tasked to find out where all of our storage has gone and because this SAN LUN is shared between a multiple of systems I have decided to generate the report based on Folder size within the LUN. Please see below for the script to run from PowerCLI

$searchSpec1 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec1.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec1.details.fileSize = $true
$searchSpec1.query += New-Object VMware.Vim.FolderFileQuery
$searchSpec2 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec2.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec2.details.fileSize = $true
$searchSpec2.query += New-Object VMware.Vim.FileQuery
$report = @()
Get-Datastore | Get-View | % {
$browser = Get-View -Id ($_.Browser)
$dsPath = "[" + $_.Summary.Name + "] /"
$folderList = $browser.SearchDatastore($dsPath, $searchSpec1)foreach($folder in $folderList.File){
$folderPath = $dsPath + $folder.Path
$fldresult = $browser.SearchDatastore($folderPath, $searchSpec2)
$fldSize = 0
foreach($file in $fldresult.File){$fldSize += $file.FileSize}
$row = "" | select DSName, FolderName, FolderSize
$row.DSName = $folderList.FolderPath
$row.FolderName = $folder.Path
$row.FolderSize = $fldSize
$report += $row
}
}
$report | Export-Csv "c:\powershell\Foldersize.csv" -noTypeInformation

Once you have harvested your CSV import it into excel and use the following on the custom format for file size

[<500000]#,##0" B ";[<500000000]#,##0,," MB";#,##0,,," GB"
PS: GUI Building Made Easy

PS: GUI Building Made Easy

Okay so when it comes to doing form building in raw PowerShell the formatting can be a complete pain in the ass. So I have been searching online that’s pretty dangerous for me I never know what I might find but on this occasion I have found an awesome tool from Sapien Technologies called Primal Forms CE the only issue I wasn’t able to find a download link for the application and it looks like they have discontinued it for free use but don’t worry I managed to find it sitting on an old mirror and I have left a copy of it on my OneDrive for all of you to download.

So what does it do?

In essence it is a simple drag and drop environment for designing your GUI that is then exportable into raw PowerShell code. Saving you the time and the headache of trying to format it in code

Screenshot:

c8353444d582ed3d820731582abf994d

Download Link:

https://1drv.ms/u/s!Amaaew76M7RY1Wo78izJXXDhhSjh