PowerCli. Automate VM deployment with static IP and some others customization.

Recently I’ve been requested to deploy plenty of virtual machines with static IP address and custom password. These VMs should not be controlled by our IT department so I cannot use tools like Config Manager.
I decided to write a custom PowerShell function and share with you. My script require you to be connected to the vcenter with PowerCli module as well as required permission to deploy VM.
You can add forEach loop and pass a CSV file to run script.

Some parameters will be checked prior VM creation, such as:
Datastore Name
VM name, if name already exsist
Resource pool and folder (folder will be created if script won’t find one)
VM cluster if exsist
Provided disk capacity must be greater that source VM

Here is the script:

You should see progress in on your console, here is how it looks like:

You can grab script here.

Feel free to add more functionality if you want or make some piece of code more effective.
This script works with one disk and one network adapter, so you can add these features and of course one good thing is RunOnce that VmWare supports in their PowerCli modeule you should’t forget about.

Keep scripting.

Powershell. Get computers from Active Directory with low disk space.

We have float pool in VMware Horizon and often C: disk is running out of space.
Here is a quick script that I wrote to get all computers from AD with low disk space.

Of course you can wrap it into function, add email notification or make some peace of code better, but I’m to lazy to do it:)
Here is how it’s looks like:

You just need to change $lowspaceGB to any disk space you need and $OU to yout target ou.
Also this script required ActiveDirectory powershell module on computer which run this code and winRM ports must be opened on target computers.

This script will ping every pc in OU and if computer will reply then disk space will be evaluated and printed out to console.

$lowspaceGB = "19"
$OU = "OU=Horizon-VDI,OU=CR,DC=Domain,DC=com"

$allpcs = Get-ADComputer -SearchBase $OU -Filter *
$availablepcs = @()
$lowspacepc = @()
$allpcs | %{
if (Test-Connection $_.DNSHostName -Count 1 -ErrorAction SilentlyContinue){
$availablepcs += $_.DNSHostName
foreach($pc in $availablepcs){
$freespace = (Invoke-Command -ComputerName $pc -Command {Get-PSDrive C}).Free
if ($freespace/1GB -lt $lowspaceGB){
$obj = New-Object System.Object
$obj | Add-Member -Type NoteProperty -Name "DNSHostName" -Value $pc
$obj | Add-Member -Type NoteProperty -Name "FreeSpaceGB" -Value ([math]::truncate($freespace/1GB))
$lowspacepc += $obj

Download script.

Powershell. Notify Users by email if their accounts is close to expiration date.

Here is a script which will help you to notify users if their account will be expired soon.
In my case I will use this script to notify 3rd users that they need to write request if prolongation required.

You can download script from here.

Have a nice Day.

Exchange. Change TimeZone via Powershell.

Due many requests about TimeZone settings in Exchange I decide to share additional solution.
As you may know from previous post DST is cancelled for AZT time zone.

Exchange doesn’t use your computer time setting for mailboxes and therefore when you will switch DST off on your server- OWA will ignore this and time will be shifted for a one hour for Web Clients.
To avoid problem with OWA and your Web Calendar you should use following command:

This will get all mailboxes with AZT timezone and change it to Arabian Standard Time.
You should change it back when exchange will update their timezone db.

Microsoft will distribute DST patch approximately with regular “Second Thuesday Update” on May.

Change TimeZone and DST setting via Group Policy. Step-by-Step Guide.

Dear Colleagues from Azerbaijan, Now Time will not be adjusted to summertime and probably no one OS vendor will publish a new timezone file in this month.
To change time for all computers we need to create a GPP and apply to all computer (We can create a script which will use tzutil.exe but legacy systems lack of this app).
First please apply my register file, it will set AZT time with Daylight Saving Off.
Let’s create our policy with register wizard, start gpmc.msc
Open key that you imported:

Select Key and all value.

Copy DisableAutoDaylightTimeSet (Right click—>;Copy—>>;Pate) from this GPP and edit and change action from update to create for one of key.

Policy ready and you can deploy it for your computers.
But here is a one thing that we need to know, time setting will be applied when Windows Time service (W32Time) will reload configuration. To force reload time config you can use PSExec (From Systinternals suite, you can direct download from here or from Microsoft Site) to run ‘net stop w32time && net start w32time’.
I can’t run following command from my DC because of exception:

Therefore, following script will be executed from Powershell with AD Modules installed:

You might know that Kerberos protocol use timestamp when generate ticket and maximum time skew between DC and Computer by default is 5 minutes. To avoid problems with machine who is offline now you can temporary change this setting to 65 minutes and remove them when all your computers will pool your latest GPO.
You can change default settings from “Default Domain Policy” or can create your own policy (but make Policy Precedence order lower if you will create new policy file).


P.S. You can adjust all settings via Powershell and the only reason I use PSExec is to execute command across all device include legacy computers without PS.

Have a nice Holidays!