Posts

Showing posts with the label Name

Creating Unique Names for Resources in Bicep

Image
When creating resources on Azure, there are times that the deployment fails due to the name selected for the resource. This is primarily due to the fact that there are some resources that are available as services and exposed to the internet, thus their name should be unique across deployments.  Take a storage account for example. The name should not only be unique but also in lowercase and under 25 characters! A virtual machine, on the other hand, does not require a unique name (at a global level). How do we tackle such requirements? The Bicep uniqueString function is here to help. This particular function takes a number of string parameters and creates a unique string. Combined with scope functions like subscription and resourceGroup , you may generate strings unique to your environment. Other string functions like toLower  and substring  can be used to make your code even more robust. Let's dive into some examples! The below code is part of a bicep file that deploys ...

Getting the Object Type in PowerShell

First post of the year and in a while and I would like to talk about the types of the objects in PowerShell. Much like C#, each object has a type in PowerShell. This type is proven to be very helpful when developing functions and cmdlets since it provides information about the object we are dealing with. For example you may have a variable that holds the value "1" but it can be of type string, integer, double and others. The way to differentiate is to examine the type of the variable. There are may ways to get the type of a PowerShell object but first, let's get the newest event in the application log to use as example: PS C:\> $obj = Get-EventLog -LogName Application -Newest 1 PS C:\> $obj Index Time         EntryType   Source InstanceID Message ----- ----         ---------   ------ ---------- ------- 3882  Jan 07 20:39 Information ESENT  916        svchost (3356,...