PowerCLI: Get Snapshot Information

Get Snapshot Information KB ID 0001829

Problem

The question was asked on Experts Exchange today.

Are there any scripts or reports that would give me information on VMware VM’s with snapshots?

was pretty sure this was a straight forward one, so I jumped on the test network.

Solution: Get Snapshot Information

Connect to your vCenter and use the following commands.

[box]

Connect-viserver vCenter-Name 
THEN AUTHENTICATE
Get-VM | Get-Snapshot | Select-Object VM, Name, SizeGB, Created

[/box]

That was easy!

Get Snapshot Information : With RV Tools

You can also get the same information from RVTools, which if you don’t already use, do so!

Solution: PowerShell Delete Snapshots

You can delete all snapshots by simply piping the command above to Remove-Snapshot, But you will porbably want to do that on a VM by VM basis. Use the cfollowing command.

[box]

 Get-VM VM-Name| Get-Snapshot | Remove-Snapshot

[/box]

Related Articles, References, Credits, or External Links

NA

Find Specific GPO Settings

Find Specific GPO Settings KB ID 0001850

Problem

To find Specific GPO Settings are being applied, and which GPO is affecting which setting, you can generate an html report, there are two ways of doing this. You can either run the report on the affected machine, or if you do not have access, you can generate the same report on a domain controller (or any machine that has the group Policy Management console installed).

Solution: Find Specific GPO Settings (Locally)

On the machine in question run the following command (remember to be logged in with the credentials of an affected user!)

[box]

gpresult /h %temp%\results.html & %temp%\results.html

[/box]

It will take a little while for the report to be generated but it ‘should’ open in you default browser, like so.

From here you can see a list of all the applied GPOs, and drill down into each setting, and see the ‘Wining GPO‘ that applied that setting.

Solution: Find Specific GPO Settings (Centrally)

Most people are unaware that you can do the same from any machine that’s running the Group Policy Management administrative tool, it has a section called group policy modelling. the reason this exists is to ‘try out’ the effect of changing groups, OUs and WMI filters to see how that affects the application of GPOs to both users and computers however, if you just plus in the computer name and the users name and accept all the defaults it will give you the SAME report you generated above.

From Administrative tools > Group policy management > Group Policy modelling > Group Policy modelling wizard > Next > Next (unless you want to change the DC queried).

 

Select the user and computer in question > Next > Next  > Next.

Next > Next > Next.

Next  > Next > Finish.

The report will be rendered on screen, with the same information as if you had run gpresult manually on the client.

Related Articles, References, Credits, or External Links

NA

Install Windows Terminal on Windows Server 2022

Windows Terminal KB ID 0001827

Problem

I’ve been aware of Windows Terminal for a while, I’ve just never felt the need to set it up. Most of my work for the website involves me taking screenshots on Windows Server OS. So, when I decided to take a look at it I had to jump through a few hoops to get it to work, in the words of Juan Sánchez Villalobos Ramírez, Chief metallurgist to King Charles V of Spain, “I would save you that pain”. (If you get that reference, we can be friends).

Solution: Windows Terminal on Server 2022

So, Windows Server OSs cannot access the Windows Store, so you need to manually download the app packages (msibundle) then install them with PowerShell. If you want to install on Server 2022 then don’t download the Windows 11 package, if you do and try and install it you will see something like.

Deployment failed with HRESULT: 0x80073CFD, A Prerequisite for an install could not be satisfied. Windows cannot install package Microsoft.WindowsTerminal_1.16.10262.0_x64__8wekyb3d8bbwe because this package is not compatible with the device. The package requires OS version 10.0.22000.0 or higher on the Windows.Desktop device family. The device is currently running OS version 10.0.20348.1668

I walked back though a few versions before I realised you need to download the Windows 10 versions. go here and check for the latest version.

Previous Windows Server Versions: In some cases you may need to download and install the Preinstall kit (See above page for download link) Simply download it as a Zip file, extract it, and then use Add-AppxPackage to install the msibundle for that first. But for Server 2022 you don’t need to do that.

Firstly, you need to download another package as it’s a pre-requisite, the following commands will download and install it.

Note: Ensure C:\Temp Exists!

[box]

Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -outfile C:\Temp\Microsoft.VCLibs.x86.14.00.Desktop.appx
Add-AppxPackage C:\Temp\Microsoft.VCLibs.x86.14.00.Desktop.appx

[/box]

Once complete you can download and install the Windows Terminal Package (Check for the latest version and change the URL accordingly).

[box]

Invoke-WebRequest -Uri https://github.com/microsoft/terminal/releases/download/v1.16.10261.0/Microsoft.WindowsTerminal_Win10_1.16.10261.0_8wekyb3d8bbwe.msixbundle -OutFile C:\Temp\Microsoft.WindowsTerminal_Win10_1.16.10261.0_8wekyb3d8bbwe.msixbundle 
Add-AppxPackage -path C:\Temp\Microsoft.WindowsTerminal_Win10_1.16.10261.0_8wekyb3d8bbwe.msixbundle

[/box]

Now you can launch Windows Terminal.

Related Articles, References, Credits, or External Links

NA

vSphere Upgrade VMware Tools Suppress Reboot

KB ID 0001760

Problem

If you want to Upgrade VMware Tools and Suppress the Reboot, (because rebooting production servers is always a touchy subject), But putting ‘maintenance windows‘ and ‘CAB procedures‘ to one side. If you want to deploy new versions of VMware tools from vSphere, if you just right click and select automatically upgrade, it will reboot the server. How do you stop that happening?

Solution: Upgrade VMware Tools Suppress Reboot

Let’s start by saying that the full upgrade process requires a reboot, you will still have to do one, but it’s pretty easy to schedule that. You follow the same procedure as normal, select Automatic Upgrade, but in the Advanced Options, enter the following text;

[box]

/s /v "/qn REBOOT=ReallySuppress"

[/box]

You can actually jump on the machine and keep an eye on task manger, you will see the VMware tools stop and restart, and if you look at the installed software you will see something like the following;

Don’t forget to Schedule a reboot to properly complete the procedure.

Related Articles, References, Credits, or External Links

NA

Run PowerShell (and Command Prompt) Administratively

KB ID 0000988

Problem

We had the ‘run as’ service way back in Windows 2000, so the concept of running a command window ‘as administrator’ should not be difficult to understand. But the amount of times I tell people ‘You need to run that as administrator’, and they reply ‘I AM an administrator’ is far too high. With PowerShell theres no way of knowing, and with command prompt the differences are subtle.

Solution

There’s a myriad of different ways to launch an administrator command window, here are a few, If I’ve missed any let me know.

Launch Powershell in Administrative Mode 

Powershell administrative mode (from Within Powershell)

If you’re already in Powershell you can open an administrative Powershell window, with the following command;

[box]

Start-Process PowerShell -Verb RunAs

[/box]

Powershell Administrative Mode (from Start Menu)

Option 1: From Start/Search > Powershell > Right Click Windows PowerShell > Run as administrator.

Option 2: Start > Right Click Windows PowerShell > Run as administrator.

Option 3: Start > Windows PowerShell > Windows Powershell > Run as Administrator.

Option 4: Right Click Start Menu (or Press Windows+X) > Window Powershell (Admin).

Powershell Administrative Mode (from Task Manager)

Launch Task Manger > File > Run new task > Powershell > Tick ‘Create this task with administrative privileges’.

Powershell Administrative Mode (from Windows Explorer)

From Windows Explorer > File > Open Windows PowerShell as administrator.

Launch Command Prompt in Administrative Mode 

Administrator Command Prompt From Start Menu. (Windows 10 and Server 2016/2019)

From the Start/Search option > Type cmd > Then right click Command Prompt and select ‘Run as administrator’.

Command Prompt (Admin) – Windows 10 (& Server 2016/2019) 

Right click the Start Button > Command Prompt (Admin)

Command Prompt (Admin) – Windows 8 (& Server 2012) Quick Links Menu

Press Windows Key+X > Select Command Prompt (Admin)

Administrator Command Prompt From Start Menu. (Windows 8 and Server 2012)

If you have the new Windows 8/2012 Start Menu (that we can’t call Metro any more) then type ‘command’ in the search window, then either right click and select ‘Run as administrator’, or press Ctrl+Shift+Enter to launch.

If you have the traditional start menu enabled or are running Windows 7/Vista, you can type command in the search/run box, then

Create An Always Run As Administrator Command Prompt Shortcut

1. Right click and empty area of your desktop > New > Shortcut.

2. Set the location to ‘cmd’ > Next > Call it Admin Command > Finish.

3. Right click your new shortcut > Properties.

4. Shortcut > Advanced > Run as administrator > Apply > OK.

 

Launch Admin Command Prompt from Task Manager.

Launch Task Manager (Ctrl+Shift+Esc) > File > Run new task > cmd > Tick ‘Create this task with administrative privileges’.

Launch Command Prompt ‘As Administrator’ From Command/Run.

I’m not a fan of this, in fact I only include it here for completeness, you can call a command windows and run it as administrator from command (or the run box (Windows Key+R). The reason I don’t like this is, you need to enter the machines local administrators password for it to work.

[box]

runas /user:%computername%administrator cmd

[/box]  

If theres any I’ve missed feel free to drop me an email, and I will update the article.

Related Articles, References, Credits, or External Links

NA

Exchange Exporting Mailboxes to PST Files

KB ID 0001360

Problem

Applicable To: This procedure works on all versions of Exchange Newer than Exchange 2010 SP1 (update rollup 8). If your Exchange server is OLDER than that you will need to use the following link;

Exchange 2007 / 2010 (Pre SP1)- Export Mailbox’s to PST files

The following procedure exports a user mailbox to a PST file on a network share.

Solution

Note: Not Even ‘Exchange Organisation Administrators” have the right to import / export mailboxes, you need to grant those rights to your user object, (or a better approach would be to create an admin account just for this purpose, then delete it when you are finished).

[box]

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User {username}

[/box]

Note: This grants import, and export rights.

Create a file share on a drive with plenty of space, ensure the Exchange Trusted Subsystem has read / write access. And ensure the SYSTEM account has full control.

To create the ‘Export Request’

[box]

New-MailboxExportRequest -Mailbox “mailbox-alias” -FilePath \\server-name\share\file-name.pst

[/box]

Note: Add “-IsArchive” to the end of the command for Archive Mailboxes.
Note2: If the export repeatedly fails, add -BadItemLimit 200 to the end and try again, you can also use the -AcceptLargeDataLoss in exceptional circumstances

To view progress;

[box]

Get-MailboxExportRequest
OR
Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

 

[/box]

When complete, you need to remove the move request(s);

[box]Get-MailboxExportRequest | Remove-MailboxExportRequest
OR (If you still have movement requests running)
Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest[/box]

Using Content Filters

You can specify a content filter to only export emails after a certain date all mail received after 01/01/17 e.g.

[box]New-MailboxExportRequest -Mailbox {mailbox-alias} -ContentFilter {(Received -lt ’01/01/2017’)} -FilePath \\{server-name}\{folder}\{file-name}.pst[/box]

Or to export emails between two dates;[box]New-MailboxExportRequest -ContentFilter {(Received -lt ’31/12/2018‘) -and (Received -gt ’31/12/2017′)} -Mailbox {mailbox-alias} -FilePath {server-name}\{folder}\{file-name}.pst[/box]

Using IncludeFolders (and Exclude Folders)

You can specify IncludeFolders (or ExcludeFolders) to only export emails from certain folders, e.g.

Only export Inbox (and sub-folders) and Sent Items;

New-MailboxExportRequest -IncludeFolders “#Inbox#/*”,”#SentItems#” -Mailbox {mailbox-alias} -FilePath \\{server-name}\{folder}\{file-name}.pst

Don’t Export Sent Items and Deleted Items;

New-MailboxExportRequest -ExcludeFolders “#SentItems#”,”#DeletedItems#” -Mailbox {mailbox-alias} -FilePath \\{server-name}\{folder}\{file-name}.pst

Export ALL Mailboxes to  PST

[box]foreach ($Mailbox in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $Mailbox -FilePath “\\{server-name}\{folder-name}\$($Mailbox.Alias).pst” }[/box]

Related Articles, References, Credits, or External Links

Exchange 2000 / 2003 – Exporting Mail to .pst files with ExMerge

Exchange (2010 Post SP1 and Newer) Bulk Importing Mail From PST Files

Remotely Log Users Off From CLI / PowerShell

KB ID 0001401

Problem

I’ve not had to do this since the days we got “The terminal server has exceeded the maximum number of allowed connections” errors. Now thankfully Windows Server tells us who is logged on so we can ‘ask politely’ before we boot them off!

Today though, my user session got all messed up, and I needed to kick ‘myself’ off remotely, (and have a fresh session.)

Solution

From a remote machine run the following command, to see who is logged on and, (more importantly get the session number for that user);

[box]QUser /SERVER:{Hostname}[/box]

Above the ID of ‘1’ denotes the session number, select the one that corresponds with the user you want to log off. Then issue the following command;

[box]Logoff /SERVER:{Hostname} /{Session} /V[/box]

Job done, that was easy!

Related Articles, References, Credits, or External Links

NA

Windows – ‘Sorry, there was a problem mounting the file’ With ISO Files

KB ID 0001122 

Problem

Seen on Windows 10, and Server 2012, when attempting to open or mount an ISO file, (even downloaded direct from Microsoft). You get the following error;

Note: Can also been seen with .VHD files.

Couldn’t Mount File

Sorry, there was a problem mounting the file.

Solution

Before you try anything else simply COPY the iso file to the root of your C: drive, and try again.

99% of the time simply copying the file to the C: drive will fix the problem, but if you’re still reading then that’s probably not the case for you? The problem is most likely that the ISO file has had the sparse attribute set.

Option 1

Download Remove Sparse > Extract the Contents and > Run the .reg file.

Now you have the option to remove Sparse on the right click menu.

Option 2

You can open an administrative command window and remove the sparse attribute from command line;

[box]

fsutil sparse setflag {Path to the .iso file} 0

fsutil  sparse queryflag {Path to the .iso file}

[/box]

Related Articles, References, Credits, or External Links

NA

ESX – Shut down from Script/Command

KB ID 0000279 

Problem

I was asked the question last week “How do I shutdown my ESX server remotely from script”. The client had a temperature sensor in their server room and wanted to shutdown their ESX host if it got too hot, all his Windows servers got sent an SNMP trap from the temperature sensor, and that fires off a script to shut down the Windows servers. But this left the ESX host up and running.

Solution

I drew a blank on getting a shell script to fire when an SNMP trap is received on ESX, but there’s nothing to stop me adding a line to one of the Windows server scripts that would shut down the ESX server.

1. Firstly get all your Guest VM’s to shutdown automatically when the host is shut down > In the VI client > Select the host > Configuration > Virtual Machine Startup/Shutdown > Properties.

2. Tick the box marked “Allow virtual machines to start and stop automatically with the system” > Change the “Shutdown Action” option from “Power Off” to “Guest Shutdown”.

3. Select Each guest VM and click the “Move Up” button so that are all in the automatic startup section > OK.

WARNING – this is not supported on ESX4 for guest VM’s in a High Availability cluster. (page 22).

4. I’m going to shutdown using the root account, for this to work you need to allow SSH access to the root user see HERE.

5. Download a copy of plink.exe and put it in the same directory as your script (or the system32 directory on the windows machine).

6. Add the following line to the bottom of your script,

[box]plink -ssh root@172.16.254.209 -pw password123 poweroff -p[/box]

Note: where password123 is the root password, and 172.16.254.209 is the IP of the ESX server.

7. When the line is executed, the guest VM’s will shut down, then the ESX Server will power off.

In the VI client you will see the guests shutting down.

Related Articles, References, Credits, or External Links

NA