≡ Menu

This article will help you understanding how to configure Memory (both static and Dynamic) on a Hyper-V Virtual machine. You can increase or decrease memory using the PowerShell scripts given in this article.

Ever since I am running my test lab on Windows Server 2012 Datacentre edition, I have been playing with various options in the OS and especially Hypervisor. I have multiple VMs running in the Hypervisor and today I wanted to increase Memory of one of my virtual machine name Infra2. I know it is very easy to do it from Hyper-V Manager but my love towards PowerShell won’t let me do that way. So started looking at options for increasing memory of my virtual machine from 1GB to 2GB using PowerShell code.

The Hyper-V PowerShell module in Windows Server 2012 has two cmdlets for adjusting the memory configuration of Virtual Machines. One is Set-VM and another is Set-VMMemory. While the first one is used for modifying any configuration of Virtual Memory, second one is explicitly designed to change memory configuration. In this article I will focus on Set-VM cmdlet.

Windows Server 2012 Hyper-V comes with Dynamic Memory concept. If you haven’t heard about it, you can try this TechNet page for more details. Using Set-VM cmdlet, we can set both Dynamic and static Memory of virtual machine. Let us start looking into some of the examples.

First let us see how to check the current memory configuration. Using Get-VM cmdlet we can see what is the current memory assignment, whether it is static or dynamic memory, if dynamic memory what is the max and min values.

Get-VM -Name Infra2 | select *Memory*
Virtual Machine Memory Change Powershell

The above output is pretty much self-descriptive. I want you to make a note of DynamicMemoryEnabled property value. If it is true, you have dynamic memory enabled. A False value like shown in above screen indicates that it’s a static assignment. In case of static assignment, MemoryStatup is the value that we need to focus. The value stored in this property is bytes.

So, now let us go ahead and see how to change the memory of this VM from 1GB (1073741824 in bytes) to 2GB. It is as simple as executing below command.

Set-VM -StaticMemory -Name Infra2 -MemoryStartupBytes 2GB

Now you verify your memory values again using Get-VM cmdlet and you will see new value in the MemoryStartup property.

Similarly, if you want to increase memory values in case of Dynamic memory, just do your math and come up with what values to you want to give for MemoryStartup, MemoryMinimum, MemoryMaximum properties and assign them like shown below. In the below example, I want my VM to start up with 1GB of RAM and can utilize up to 2GB and minimum value is 500MB.

Set-VM -Name Infra2 -MemoryStartupBytes 1GB -MemoryMinimumBytes 500MB -MemoryMaximumBytes 2GB

Hope this article helps and happy reading…

{ 2 comments }

Mount ISO file using Powershell

In this post I will show you how to mount a ISO file using Powershell in Windows Server 2012 and Windows 8 using native cmdlets. I will also explain how to get the drive letter of already mounted ISOs.

We all are aware that ISO files can be mounted as drives in Windows XP/7/8, windows server 2003/2008/2012. While it can be mounted on XP/Windows7 or Windows Server 2003/2008 using third party tools like “Virtual CD/DVD-ROM” from Magic ISO, Windows 8 and Windows Server 2012 provides direct ability to mount ISO files as physical drives. It is not that only ISO can be mounted, we can also mount exisiting VHD files and VHDX(new format of Hyper-V disks) files using the powershell commands in Windows Server 2012 and Windows 8.

I downloaded a Visual Studio ISO for my development requirements and I will show you how to mount that ISO using Powershell. In Windows Server 2012 and Windows 8, there is function called Mount-DiskImage in Storage module that comes by default with the OS installation. This cmdlet can be used to mount the ISO files.

This Mount-DiskImage function takes path of Image file using the -ImagePath argument and type of Image file using -StorageType argument. The -ImagePath argument is mandatory and StorageType argument is optional. When storageType argument is not specified it picks the storage type using the extension of file that you provided.

What I feel missing in this cmdlet is, ability to provide drive letter to which it should be mounted. That will help us easily determine the drive letter without scripts after mounting the ISO file.

Below is the command to mount the ISO file.

Mount-DiskImage -ImagePath c:\local\VS2012_WDX_ENU.iso

This function will not show any output after successful completion, but it will report errors if there are any. Similarly you can pass VHD or VHDX files to mount as physical drives using this function.

If the ISO you are trying to mount is already mounted as physical drive, then you will see error message like below.

Mount-DiskImage : The process cannot access the file because it is being used by another process.At line:1 char:1+ Mount-DiskImage -ImagePath C:\Users\administrator.AD\Downloads\VS2012_WDX_ENU.is …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (MSFT_DiskImage …torageType = 1):ROOT/Microsoft/…/MSFT_DiskImage) [Mou   nt-DiskImage], CimException    + FullyQualifiedErrorId : HRESULT 0x80070020,Mount-DiskImage
If you want to know what is the drive letter assigned this ISO file after mounting, you can find it by using below command.

Get-DiskImage -ImagePath c:\local\VS2012_WDX_ENU.iso | Get-Volume

This will display the drive letter and other details as shown in below output.

Hope this article helps and happy learning.

{ 0 comments }

In this post I will show you how to disable Server Manager Start up during user logon on Windows Server 2008 R2 and Server 2012

Server Manager start-up during Windows User logon on Windows Server 2008 R2 server Operating system is the most frustrating thing for System administrators who manage the boxes. We know that it exists and how to launch so we would like to get it disabled from user logon start-up.

First we will see how we can solve this problem in different ways and then we will come to the topic where each one should be used.

There are two methods using which we can disable Server Manager launching from Start at the time of user login.

Registry Method:

There are two registry keys to be modified to address this problem.

Set the value of below key to 1

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\DoNotOpenServerManagerAtLogon

And set the value of below key to 0

HKEY_CURRENT_USER\Software\Microsoft\ServerManager\CheckedUnattendLaunchSetting

The HKLM key prevents the Server Manager start-up for any new logins to the server. For existing logins, the second HKCU key helps. That means, if you already have some user profiles created on the server then you should consider deploying the above HKCU to the respective user hives. While deploying the HKLM key can be done via Powershell script (discussed at this 4sysops article), deploying HKCU should be done via Group Policy preferences or logon scripts.

Group Policies Method:

Server Manager Start-up can be done via Group Policies as well.

The policy “Do not display server manager automatically at logon” is under “Computer Configuration\Administrative Templates\System\Server Manager” container in group policy editor. You can either create a new policy or use existing policy to add this new setting based on the scope and other requirements. Once the policy is configured deploy it to required servers. Unlike Registry method, this group policy method works for both new users logging into the server as well as existing users.

What is preferred approach?

In my opinion, the Group Policy approach is much appropriate and suitable deploying to multiple computers. It is easy to deploy or revert since the Group policy modification is matter of seconds. The registry method also works but you need to come up with custom scripts to deploy HKLM keys and other alternatives to deploy HKCU keys which is not an easy task.

Hope this helps and happy learning.

{ 4 comments }

Start a Hyper-V virtual Machine using Powershell

In this post, I will show you how to start one or more virtual machines residing on Microsoft Hyper-V using Powershell commands.

Microsoft Hyper-V module for Powershell has 164 cmdlets on Windows Server 2012 to install, configure and manage Hyper-V environment, VMs, v-switches and other components of MS virtualization.

In this article I primarily focusing on how to start one or more virtual machines using Powershell. The Hyper-V module has a cmdlet called Start-VM(similar to Start-VM in VMwareCli) to start Virtual Machines on MS Hyper-V server. This cmdlet has two important arguments named -ComputerName and -Name. The ComputerName parameter refers to Name of the Hyper-V server where the Virtual machines are hosted and Name parameter refers to actual name of the Virtual Machine that you want to start. Here please note that you should pass display name of the virtual machine that you see in Hyper-V Manager UI, not the actual Operating System name of the virtual Machine.

First of all we need to import the Virtual Machine. We can do this by executing below command from a Powershell window.

Import-Module Hyper-V

Once imported, use Start-VM cmdlet to start the Virtual Machine.

Start-VM –Name Infra1

In the above example, I haven’t provided any Hyper-V server name because by default the cmdlet tries it on local server. In my case, I am executing these commands from a shell on Hyper-V server where my VM is located.

To start a VM hosted on remote Hyper-V server, you can specify the name of remote Hyper-V server to the ComputerName parameter. See below example.

Start-VM –ComputerName MyHyperv2 –Name Infra1

Similarly you can start multiple Virtual machines by specifying their names to Name parameter as shown below.

Start-VM –ComputerName MyHyperv2 –Name Infra1,Infra2

Hope this helps and happy learning.

{ 2 comments }

Enable Wireless connection in Windows Server 2012

In this post, I will show you how to enable Wireless connection in laptop after installing Windows Server 2012.

After a failure attempt to install Vmware server on my laptop, I decided to switch to Hyper-V as my hypervisor to host VMs. I downloaded VHD file of Windows sever 2012 and booted my laptop from that(I will cover this boot from VHD in a upcoming posts) downloaded VHD. Everything was fine, except my server OS is not coming into network. The wireless connection was not working and in disabled state like shown in below picture.

Since Network connection is very much required for my lab setup, I decided to explore it more. One option is, I can use a Wired connection to get internet and network but that will defeat the purpose of laptop. So I checked why wireless connection is not working. While exploring the features list via “Add roles and features wizard” in server manager I stumbled on the feature called “Wireless LAN service”. I quickly enabled the feature using the below powershell commands.

Import-Module ServerManager            
Add-WindowsFeature -Name Wireless-Networking

and the output is something like below and I restarted my laptop to finish the installation.

After rebooting the laptop I verified the status of my wireless connection again, and to disappoint me, it is in the same disabled state. Then after some googling, I went into device manager on my windows server 2012, and tried upgrading the wireless card drivers and it worked like a champ.

Now I have wireless enabled and working on my laptop with Windows server 2012 OS.

Hope this helps and happy learning.

{ 1 comment }

SMB (Server Message Block) — my today’s learning

Ever since I started managing Windows boxes, I am familiar with this word, SMB (Server Message Block). What it does? — it helps in accessing files on remote file System or on another windows server. What ports it uses 139 TCP, 138 UDP, 137(TCP/UDP) and 445 sometimes. So my answer to questions like what ports you need to access file shares on a server behind firewall is all aforementioned ports.

Well, that’s old story now. Today I got a chance to look much deeper into SMB protocol while helping one of my friend(and senior) to debug a problem. Let me ramble what I learned.

When Microsoft originally designed SMB, it was a wrapper on top of NetBIOS API. It used to use NetBIOS functions to access files on remote file systems over TCP. In those days, SMB used to use ports 137(tcp),138(udp) and 137(tcp&udp) for communication with other Systems. As the things improved and NetBIOS has became a legacy system. MS also want to get rid of it(not that easy at this moment I think). Since improvements to SMB are blocked by abilities of NetBIOS, they started making SMB independent of it called Direct-SMB. This Direct-SMB uses the port 445(TCP) for file sharing.

That is the story behind and now coming to the context of Windows Administrators, you need to understand which version of SMB your computer(s) are using. If the client computer has NetBIOS disabled, it tries to connect to the file server on port 445 for file access provided the file server is Windows server 2000 or above. If the client computer has NetBIOS(and WINS) enabled, the client computer uses NetBIOS and tries to contact file serve on 137(tcp),138(udp) and 137(tcp&udp) ports. Though Microsoft moved to Direct-SMB still they are supporting SMB over NetBIOS because many legacy systems are still using old APIs for data transfer. If a client tries to communicate using NetBIOS API, the server replies with same protocol.

How do you know if a computer has NetBIOS over TCP/IP enabled:

Just run the one of the below commands.

  • net config redirector
  • net config server

Verify NetBIOS over TCP/IP Status

If output contains NetBT_Tcpip, that means you have NetBIOS over TCP/IP enabled. You will see NetbiosSmb. Below is screenshot from my Windows 8 computer.

Disable NetBIOS over TCP/IP

If you want, you can disable NetBIOS over TCP/IP by following below steps.

  1. Click Start, point to Settings, and then click Network and Dial-up Connection.
  2. Right-click Local Area Connection, and then click Properties.
  3. Click Internet Protocol (TCP/IP), and then click Properties.
  4. Click Advanced.
  5. Click the WINS tab, and then click Disable NetBIOS over TCP/IP.

Conclusion:

So when anyone asks what ports required for access files share on a behind firewall server, my next question would be “Is NetBIOS over TCP/IP enabled or disabled?”.

Thanks for reading. Hope you learned some time too. Happy learning.

 

{ 0 comments }

PowerShell: Query VMware VM hard disk data store name

In this post I will show you how to query the datastore name given Virtual Machine name in VMware.

Let us see what is involved in querying the data store name of a VM hard disk. At first glance you might think that below command will give you the information you need and there is no complexity. But the actual fact is that, below command returns the datastore name where the VM is stored(that is VMX file) but not the location of hard disks.

Get-DataStore -VM (Get-VM -Name MyVM1)

So, what is the approach should be? Per my research, there is no straight forward way to get this information, but what we can do is derive this from one of the existing properties. Let us see how to do that.

The Get-HardDisk cmdlet returns array of harddisk objects and each object will have a property called filename. This file name property contains path to HDD file in the datastore. Extracting the datastore name from the FileName property is the only way to get datastore name of the hard disks.

$VM = Get-VM -Name MyVM1            
$Disks = Get-HardDisks -VM $VM            
foreach($disk in $Disks) {            
$FileName = $Disk.FileName             
$Diskname = $Disk.Name            
$datastore = $FileName.split("]")[0].split("[")[1]            
"{0} : {1}" -f $Diskname,$datastore            
}

Hope this helps… Happy learning…

{ 3 comments }

Never ignore built-in/native commands in Windows

This post is based on my today’s learning.

Before I started using Powershell, shutdown.exe was the only command that I used to shutdown multiple remote computers. But I felt really inconvenient with it because, I had to use some batch scripting to shutdown multiple  remote computers. Even till Powershell V2 I relied on this utility to shutdown multiple computers by wrapping some code around it.

Well, there is no problem with the usage, but for the first time I have seen a very useful option in this tool. That is GUI. I never knew that shutdown.exe has UI. I never knew it because, I never cared to read what this tool offers me by looking at command help. You might wonder what is so special about this UI.

So, dear system admins, The point I want to make is read the help message of a native tools carefully, they might ease your task. No need to always develop complex scripts/automation for simple tasks.

Look at the below screenshot.

Using this UI,

  • You can shutdown multiple computers by pasting the list after selecting add button.
  • You can shutdown all computers in a OU using a single click.
  • You can shutdown, restart, and mimic a unexpected shutdown as well.
  • You can set the timeout you want
  • You can provide the reason for shutdown and comment as well. This goes to multiple computers

 

Hope this helps.. Happy learning…

{ 2 comments }

Get VMware VM Disk size using powershell

In this post, I will talk about querying the disk size details of a VMs in VMware ESX environment.

First of all you need to connect to Virtual Center where your VMs are hosted. As you already know, use the below command from PowerCLI console.

Connect-VIServer -Server VCServer1

Once connected to VC, we need to get the VirtualMachine Object of VM that we want to query for disk size details.

$VMObj = Get-VM -Name $VMName

Above command will get the Object of Virtual Machine. In previous version of PowerCLI, the disk details are generally part of VM object returned by Get-VM cmdlet. The latest versions are a bit different, and you need to use Get-HardDisk cmdlet.

$Disks = Get-Harddisk -VM $VMObj

The Get-HardDisk cmdlet returns array of disks that are connected to the VM. To get the details of each disk, you need to loop through the returned array and get the required properties.

So, here is the complete combined code:

function Get-VMDisks {            
[cmdletbiding()]            
param(            
[string]$VMName            
)            
$VMObj = Get-VM -Name $VMName            
$Disks = Get-Harddisk -VM $VMObj            
foreach($disk in $Disks) {            

$DiskName = $Disk.Name            

$DisksizeinGB = ($Disk.CapacityKB * 1024)/1GB            

"{0} : {1}" -f $DiskName, $DisksizeinGB            

}            
}

Hope this helps…

{ 1 comment }

I got my first personal laptop last weekend. Since I want to run couple of VMs, went for a bit high configuration. While setting up VMware Server on this laptop, I experienced a problem where drivers signing is failing on Windows 8. A quick search in Google suggested that I should disable driver signature enforcement on my Windows 8 computer with the help of below commands.

bcdedit -set loadoptions DDISABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING ON

I went ahead with above commands but the second one is failing with below error message

An error has occurred setting the element data. The value is protected by Secure Boot policy and cannot be modified or deleted

I made sure that I am running this in elevated command prompt but it didn’t help. After some struggle I came to know that there a feature in BIOS(called as secure boot) that restricts modification to some of the boot loader features. So, I went into the BIOS and searched for some thing that represents “Secure Boot” and disabled it. After that I am able to run command without any issues.

Hope this helps..

PS: You might want to ask whether it allowed me to install VMware Server on my Windows 8 laptop. Answer is NO. I am still facing the driver signature verification issue and the installation keep failing. Vmware services are not starting after the installation. I am still troubleshooting this on my PC; will make a separate post about it.

{ 2 comments }