Azure Resource Group is a container that stores the resources like Virtual Machines, Storage, IP addresses, etc. To create a new Azure Resource group, we need to use the New-AZResourceGroup command.To use this cmdlet, you first need to connect to the Azure account, and then if you want to create a resource group for the particular subscription you need to select that subscription.To create a new resource group, you need the location for the resource group. The below code will first connect to your Azure account, selects the Azure subscription, and then creates a new resource group.Example$ErrorActionPreference = "Stop" Connect-AzAccount Set-AzContext -SubscriptionName 'Enter your subscription name here' New-AzResourceGroup -Name 'TestRG' -Location 'Central US' -Tag @{'RG'='APP'}OutputResourceGroupName : TestRG ... Read More
To get the available resources from the resource groups using PowerShell, we need to use the Get-AZResource command. Suppose we have the resource group name AnsibleTestRG and we need to retrieve the resources from the resource group, then we will use the below command.ExampleGet-AzResource -ResourceGroupName AnsibleTestRGTo filter the output, OutputGet-AzResource -ResourceGroupName AnsibleTestRG | Select Name, ResourceType, LocationOutputIf there are multiple resource groups in the particular subscription, we can use the below commands to export the resources from the resource group to the CSV file.Example$ErrorActionPreference = "Stop" try { Connect-AZAccount Set-AzContext -SubscriptionName 'Your Subscription Name' $rgs = Get-AzResourceGroup ... Read More
To check if the resource group is empty or not we need to check if the resource group contains any resources.For this example, We have a resource group name called the TestRG and we need to check if it is empty.Example$resources = Get-AzResource -ResourceGroupName TestRG if($resources){"Resource group is not empty"} else{"Resource group is empty"}OutputResource group is emptyTo check if the resource groups in the particular subscription are empty or not, use the below code.OutputConnect-AZAccount Set-AzContext -SubscriptionName 'Your Subscription Name' $rgs = Get-AzResourceGroup Write-Output "Empty Resource Groups" foreach($rg in $rgs.ResourceGroupName){ $resources = Get-AzResource -ResourceGroupName $rg if(!($resources)){ $rg } }Read More
To create a temporary file with the PowerShell, we can use the New-TemporaryFile command. This command creates a temporary file tmp.tmp where NNNN represents the random hexadecimal number.ExamplePS C:\> New-TemporaryFile Directory: C:\Users\Administrator.AUTOMATIONLAB\AppData\Local\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 4/10/2021 9:14 PM 0 tmpF624.tmpThe output path is selected based on the path defined at Path.GetTempPath() https://docs.microsoft.com/
To get the disk performance using PowerShell, we need to use the Performance counter of the disk. There are performance counters available for the Physical disk or the logical disk. To check what the disks related counter sets are available we can use the below command, ExamplePS C:\> Get-Counter -ListSet "*disk*" | Select CounterSetNameOutputCounterSetName -------------- FileSystem Disk Activity Storage Spaces Virtual Disk LogicalDisk PhysicalDiskWe will use a Logical disk to get more information about it. We will retrieve its counter first.ExampleGet-Counter -ListSet LogicalDisk | Select -ExpandProperty CounterOutputWe need to retrieve the Disk read time counter, ExampleGet-Counter -Counter '\LogicalDisk(*)\% Disk Read ... Read More
To get all the process-related counters, you need to use the below command.ExampleGet-Counter -ListSet "*Processor*" | Select CounterSetNameOutputCounterSetName -------------- Processor Information Per Processor Network Activity Cycles Per Processor Network Interface Card Activity Hyper-V Worker Virtual Processor Hyper-V Hypervisor Virtual Processor Hyper-V Hypervisor Root Virtual Processor Hyper-V Hypervisor Logical Processor Processor Processor PerformanceNow let say we need the Processor Performance counter set then we can use the below command to retrieve all its counters.PS C:\> Get-Counter -ListSet "Processor Performance" | Select -ExpandProperty Counter \Processor Performance(*)\Processor Frequency \Processor Performance(*)\% of Maximum Frequency \Processor Performance(*)\Processor State FlagsLet assume we need the processor maximum ... Read More
To get the Windows Performance counter using the Powershell, we can use the Get-Counter cmdlet.There are various performance counters available to measure the performance of the windows operating system. Get-Counter cmdlet is used to retrieve the performance of the local or the remote systems with the specific counter name.When you just run a Get-Counter command, it shows the main basic counters like Nic, Processor, disks, etc on the local system. as shown below.ExamplePS C:\> Get-Counter Timestamp CounterSamples --------- -------------- 4/7/2021 7:41:42 PM ... Read More
To plot the lines first and points last, we can take the following Steps −Create xpoints, y1points and y2points using numpy, to draw lines.Plot the curves using the plot() method with x, y1 and y2 points.Draw the scatter points using the scatter method.To display the figure, use the show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 1.5, 10) y1points = np.log(xpoints) y2points = np.exp(xpoints) plt.plot(xpoints, y1points) plt.plot(xpoints, y2points) for i in xpoints: plt.scatter(i, np.random.randint(10)) plt.show()OutputRead More
To create a stacked lines graph with Python, we can take the following Steps −Create x, y, y1 and y2 points using numpy.Plot the lines using numpy with the above data (Step 1) and labels mentioned.Fill the color between curve y=e^x and y=0, using the fill_between() method.Fill the color between curve y=2x and y=0, using the fill_between() method.Fill the color between curve y=log(x) and y=0, using fill_between() method.Place the curve text using the legend() method.To display the figure, use the show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 5, 100) y = x * 2 y1 = np.log(x) ... Read More
It seems difficult to change the projection of an existing axis, but we can take the following steps to create different type projections −Using subplot() method, add a subplot to the current figure, with nrows=1, ncols=3 and current index=1.Add a title to the current axis.Using subplot() method, add a subplot to the current figure, with nrows=1, ncols=3 and current index=2, projection=hammer.Add a title to current axis, hammer.Using subplot() method, add a subplot to the current figure, with nrows=1, ncols=3 and current index=3, projection=polar.Add a title to current axis, polar.To display the figure, use the show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = ... Read More