Found 2039 Articles for Microsoft Technologies

Importing / Exporting CSV file in PowerShell

Chirag Nagrekar
Updated on 18-Feb-2022 06:44:37

8K+ Views

In this article, we will work with CSV files in PowerShell which is considered one of the most efficient ways to deal with data.We have considered the below points for this article.Exporting data to the CSV file using PowerShell.Importing data from the CSV file using PowerShell.Let’s get started.Exporting data to the CSV file using PowerShellUsing Direct command outputTo export data to the csv file in PowerShell we can use Out-File which is the common cmdlet for storing the output to the file. The below command will get the top 10 CPU-consuming processes in the csv file.ExampleGet-Process | Sort-Object CPU -Descending ... Read More

Exception handling in PowerShell

Chirag Nagrekar
Updated on 18-Feb-2022 06:50:00

11K+ Views

In this article, we will go through the below points.What is an Exception in PowerShell?Terminating and Non-Terminating errors.Using Try / Catch block.Converting Non-Terminating error to Terminating Errors.Handling actual exception messages.What is the exception in PowerShell?Exception in PowerShell or other programming languages is the error or unexpected result that can be handled. For example, File not found while executing, dividing a number by zero.The exception can stop script execution if not handled properly.Terminating Errors and Non-Terminating ErrorsNon-Terminating errors don't halt script execution and it continuously runs script even if it is detected in the script. Below is an example of the ... Read More

Out-GridView in PowerShell

Chirag Nagrekar
Updated on 18-Feb-2022 06:57:40

5K+ Views

DescriptionOut-GridView in a PowerShell is the output format in the GUI format. Generally, we get the output on the console using the Format-Table or Format-List command. Similarly, Out-GridView is also the output format but we can interact with it because of the GUI format.Moreover, it provides us options to select single or multiple rows and we can store the selected output and can utilize them in the script.Out-Gridview with PipelineYou can pipeline output to the Gridview in a similar way as Format-Table or Format-List commands.Example1 − With Pipeline outputGet-Service | where{$_.StartType -eq 'Disabled'} | Out-GridViewOutputThe above command will get all ... Read More

How to get the available Azure VM sizes for the availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 12:04:54

218 Views

To get the Azure VM sizes available for the availability set, we can use the Get-AzVMSize command with the availability set name. Before running this command make sure that you are connected to the Azure Cloud (if not use Connect-AzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)Get-AzVMSize `    -ResourceGroupName MYRESOURCEGROUPAVAILABILITY `    -AvailabilitySetName myAvailabilitySetHere the Resource Group name is MyResourceGroupAvailability and the Availability set name is MyAvailabiltyset.Output

How to get the tags of the availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 12:06:32

153 Views

There are two ways to retrieve the availability set tags. Using the Tags property inside the availability tag and the second by using the Get-AzTag command.Before running this command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription).First, we will get the availability set properties and retrieve the tag property as shown below.$availablityset = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet $availablityset.TagsOutputTo get the tags using resource ID, we need to retrieve the resource ID using the Get-AvailabilitySet command.$availablityset = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet Get-AzTag ... Read More

How to find the disk type of the Azure Availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 11:58:58

212 Views

There are two types of disks available in the Availability Set.Aligned − for the managed disks.Classic − for the unmanaged disks.To get the disk types of the availability set, we first need to retrieve availability set information and then we need to retrieve the SKU property which stores the disk typesBefore running this command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)To get the availability set information, $availablityset = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet if($availablityset.Sku -eq "Aligned"){"Managed disk"} else{"Unmanaged disk"}OutputRead More

How to get the update domain count of the Azure Availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 11:54:09

183 Views

Virtual machines inside the Availability set get the update automatically, they reboot together and they are used for the patching of the virtual machines.To get the update domain count from the availability set, we can use the below command.Before running this command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)To get the availability set,$availablityset = Get-AzAvailabilitySet -ResourceGroupName Resourcegroupname -Name AvailabilitySetNameTo get the update domain count,$availablityset.PlatformUpdateDomainCountOutput

How to get the fault domain count of the Azure Availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 11:44:49

219 Views

The fault domain in the Azure Availability set describes the VMs in the availability set that share the common Power, Storage, network switch, etc. If there is a failure in the fault domain then all the resources in the fault domain will become unavailable.Before running the command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)$availablityset = Get-AzAvailabilitySet -ResourceGroupName ResourceGroupName -Name AvailabilitySetNameTo get the Fault domain countm$availablityset.PlatformFaultDomainCountOutput

How to list the Azure VMs from the Availability set using PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 11:50:46

587 Views

To list the Azure VMs under the availability set, we can use the command as shown belowBefore running the command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)$availabilitySetVMs = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySetTo get the total number of Virtual machines in the availability set, PS C:\> $availabilitySetVMs.VirtualMachinesReferences.id.countOutputTo get all the VM names from the list, we can use the below command.$VMlist = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet $i=0 foreach($vm in $VMlist.VirtualMachinesReferences){    "VM{0}: {1}" -f $i, ($vm.Id.Split('/'))[-1]    $i++ }OutputRead More

How to open port for the Azure VM using Azure CLI in PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 11:37:04

2K+ Views

To open the specific port for the Azure VM using Azure CLI, we can use az vm open-port command. Before running this command, make sure that you are connected with the Azure Cloud account and the proper Azure subscription.To open port 80 we can use the below command.az vm open-port -n Win2k16VM1 -g testvmrg --port 80The above command will open port 80 on the VM win2k16vm1 and the resource group testvmrg.To open the port with the highest priority, you can add the --priority parameteraz vm open-port -n Win2k16VM1 -g testvmrg --port 80 --priority 100To open the port range, az vm open-port ... Read More

Advertisements