Found 989 Articles for Software & Coding

How to check if the Azure resource group is empty or not using PowerShell?

Chirag Nagrekar
Updated on 12-Apr-2021 11:10:50

1K+ Views

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

How to create a temporary file using PowerShell?

Chirag Nagrekar
Updated on 12-Apr-2021 11:10:28

3K+ Views

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/

How to get the disk performance using PowerShell?

Chirag Nagrekar
Updated on 12-Apr-2021 11:08:15

5K+ Views

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

How to get the Process performance counter using PowerShell?

Chirag Nagrekar
Updated on 12-Apr-2021 11:07:51

359 Views

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

How to get the windows performance counter using PowerShell?

Chirag Nagrekar
Updated on 12-Apr-2021 11:07:01

725 Views

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

How to delete all the tags of the azure resource using PowerShell?

Chirag Nagrekar
Updated on 06-Apr-2021 08:06:13

629 Views

To delete all the tags of the Azure VM using PowerShell, we need to use the Remove-AZTag command.To delete the azure resource tags, we need its resource ID but before that, it is always better to take azure resource tags backup. You can search the question on the TutorialPoints site or google, Site − TutorialsPoint.com How to Export the Azure VM tags using PowerShell?To delete the azure Resource Tags, PS C:\> $vm = Get-AzVM -Name Testmachine2k16 PS C:\> Remove-AzTag -ResourceId $vm.Id -VerboseTo remove the azure resourceGroup tags, PS C:\> $rg = Get-AzResourceGroup AnsibleTestRG PS C:\> Remove-AzTag -ResourceId $rg.ResourceId -VerboseTo remove ... Read More

How to retrieve CSV file headers using PowerShell?

Chirag Nagrekar
Updated on 06-Apr-2021 08:04:58

5K+ Views

To retrieve the CSV file headers using PowerShell, we need to use the hidden property PSObject once we use to import the CSV file. We have a CSV file stored at the C:\temp\VMTags.csv and we need to retrieve its headers. The CSV file is as below.ABCDForPatching_DayApplicationOwnerAnsibleSundaySecretTagChiragImporting the CSV file, PS C:\> $csv = Import-Csv C:\Temp\VMTags.csv PS C:\> $csv For    Patching_Day Application Owner ---    ------------ ----------- ----- Ansible    Sunday    SecretTag ChiragExampleAccessing hidden property, PS C:\> $csv.psobjectOutputWe need to use Properties to get our values. We will get all the headers here.PS C:\> $csv.psobject.Properties | Select Name ... Read More

How to convert JSON to CSV file using PowerShell?

Chirag Nagrekar
Updated on 06-Apr-2021 08:00:52

3K+ Views

To convert the JSON to the CSV format we need to first use the ConvertFrom-JSON command. For example, we have already JSON file present with us at the C:\temp\VMinfo.JSON location. We will first import this file and then convert it to CSV as shown below.Get-Content C:\Temp\VMInfo.json | ConvertFrom-Json | Export-Csv C:\Temp\vminfo.csv -NoTypeInformationSuppose you have cmdlet that produces output in the hash table format as shown below.PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags Key             Value ---             ----- For             Ansible Patching_Day ... Read More

How to change the Azure tag value using PowerShell?

Chirag Nagrekar
Updated on 06-Apr-2021 07:59:15

1K+ Views

To change the azure value using PowerShell we need to use the Update-AZTag command with the merge property.ExampleFor example, we have the Azure VM TestMachine2k16 and we have its tags as shown below.PS C:\> $vm = Get-AzVM -VMName TestMachine2k16 PS C:\> $vm | Select -ExpandProperty TagsOutputKey          Value ---          ----- Owner       Chirag For Ansible Patching_Day Sunday Application SecretTagWe need to change the Patching_Day from Sunday to Wednesday. We will use the below command.Example$tag = @{Patching_Day='Wednesday'} Update-AzTag -Tag $tag -ResourceId $vm.Id -Operation Merge -VerboseOutputName           Value ============ ... Read More

How to get the applied azure resource tags using PowerShell?

Chirag Nagrekar
Updated on 06-Apr-2021 07:57:16

2K+ Views

To get all the applied tags to the Azure resources we need to use the Get-AZTag command and need to provide ResourceID to it. For example, We need to retrieve the Azure VM tags and we will use its resource ID.PS C:\> $vm = Get-AzVM -Name Testmachine2k16 PS C:\> Get-AzTag -ResourceId $vm.IdYou can see the output in the properties window. Another simple method is to use the Tags property for that particular cmdlet. For example, Get-AzVM, Get-AZResourceGroup, etc use the tag property for displaying the applied tags.PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags Key         ... Read More

Advertisements