Found 975 Articles for Software & Coding

How to generate an HTML report using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:16:26

5K+ Views

To generate an HTML report using PowerShell, we can use the ConvertTo-HTML command. For example, let say we need to get the services to report in HTML format then we can use ConvertTo-HTML as a pipeline.Get-Service | ConvertTo-Html | Out-File C:\Temp\Services.html ii C:\Temp\services.htmlThe first command will retrieve the output in the HTML file and the second command (ii) is the alias of the Invoke-Item command.Once you check the output, It selects all the properties of the command. To select only a few properties, you can either use the Select command or use the -Property parameter in the ConvertTo-Html command. Both the ... Read More

How to create dynamic columns (headers) in CSV using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:08:14

2K+ Views

To create dynamic columns or headers using CSV, we can use multiple methods but the one method that I find most suitable is the PSObject method.Let assume that your CSV column headers depend on the input provided by the user. Input can be a text file, user prompt for headers, array, etc. For this example, we will use the text file as input.We have the below columns (headers) to create in the CSV file.We will use the below command to create headers using PSObject and then export them into the CSV file.$object = New-Object psobject foreach($item in (gc C:\Temp\DynamicHeaders.txt)){ ... Read More

How to delete the azure blob (File) using Azure CLI in PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:06:45

5K+ Views

To delete the Azure blob using Azure CLI, we can use “az storage blob” command with the “delete” parameter. Before running this command, we first need to make sure that the azure account is connected (az login) and the proper subscription is set (az account set).To work with the azure storage account we need to authenticate to the storage. We can use storage key or the storage connections string. Here, we have shown how to retrieve the connections string.$storageaccount = 'az204storage05june' $connectionstring = az storage account show-connection-string - n $storageaccount -otsvThe below command will delete the azure storage blob named ... Read More

How to get the Azure storage container blobs (Files) using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:01:43

2K+ Views

To get blobs inside the Azure storage container using PowerShell, we will use the Get-AzStorageBlob command. . Before running this command, we need to make sure that the Azure cloud account is connected (Connect-AzAccount) and the proper subscription is set in which the storage account resides (Set-AzContext).To work with the storage accounts we first need to set the Context for it and we will use the storage account key to set the context.$rg = "az204" $storageaccount = "az204storage05june" $key = (Get-AzStorageAccountKey -ResourceGroupName $rg - Name $storageaccount)[0].Value $context = New-AzStorageContext -StorageAccountName $storageaccount - StorageAccountKey $keyWe have now created the Azure storage ... Read More

How to create the Azure Storage context using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:56:04

4K+ Views

Storage context is helpful when you are working with the Storage accounts in the PowerShell session. It is like authenticating for Azure storage. Generally, we use the Azure storage account key and the connection string to create the Azure storage context.To create a new storage context, we need to use the New-AzStorageContext command but to use this command we need a storage account key or the connection string.We will use here Storage account key. We have the resource group “Az204” and the Storage account name “az204storage05june” which are stored in a variable.$rg = "az204" $storageaccount = "az204storage05june"To get the storage account ... Read More

How to use Azure Rest API in PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:53:45

5K+ Views

To use the Azure Rest API using PowerShell, we first need to connect to the Azure cloud account using the Connect-AzAccount. Once you are connected to the Azure Account, you can use the below authorization header (same has been provided on the MS website) which contains a bearer token to authenticate the rest API.$azContext = Get-AzContext $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRm ProfileProvider]::Instance.Profile $profileClient = New-Object - TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient - ArgumentList ($azProfile) $token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId) $authHeader = @{    'Content-Type'='application/json'    'Authorization'='Bearer ' + $token.AccessToken }Once you have the Authorization header available, you can use it for authentication. Now let assume we need ... Read More

How to export output to excel in PowerShell?

Chirag Nagrekar
Updated on 01-Nov-2023 02:04:11

60K+ Views

As of now, there is no built-in command like CSV (Export-CSV) to export output to the excel file but we can use the Out-File command to export data to excel or any other file format.Let’s use Out-File to export the output of the Get-Processes command to an excel file.Get-Process | Out-File C:\Temp\processes.xlsThe above command will get all the running processes on the local system to the excel file. Let’s check the output of the excel file. You can see that the output is not in the proper excel format.One other way is to install the ImportExcel module for excel. It ... Read More

How to resolve - The underlying connection was closed - Could notestablish trust relationship for the SSL/TLS secure channel in PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 07:43:41

15K+ Views

When you run Invoke-WebRequest or Invoke-RestMethod command, sometimes you get the error “The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.” because there could be a certificate issue or the required windows version doesn’t support the TLS or SSL version. You can use the below command to bypass this error.[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}Or you can use the below code to resolve this error.Exampleadd-type @"    using System.Net;    using System.Security.Cryptography.X509Certificates;    public class TrustAllCertsPolicy : ICertificatePolicy {       public bool CheckValidationResult(       ServicePoint srvPoint, X509Certificate certificate,       WebRequest request, ... Read More

How to disable the Azure VM accelerated settings using PowerShell?

Chirag Nagrekar
Updated on 31-Aug-2021 11:00:48

265 Views

To disable the Azure VM accelerated settings using PowerShell, we need to disable the EnableAcceleratedNetworking property on the NIC attached to the VM.$vm = Get-AzVM -Name TestVM $nicname = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1] $nicsetting = Get-AzNetworkInterface -ResourceGroupName $vm.ResourceGroupName - Name $nicname $nicsetting.EnableAcceleratedNetworking = $falseIn the above example, we are setting AN settings on the Azure VM “TestVM”. To set the AN setting on the particular subscription, use the below command. Make sure that you are connected to the proper subscription using the Set-AzContext command.Get-AzVM | Select Name, ResourceGroupName, `    @{N='Accelerated Netoworking'; E={       $nic = (($_.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]       $nicsetting = ... Read More

How to enable the Azure VM accelerated settings using PowerShell?

Chirag Nagrekar
Updated on 31-Aug-2021 11:02:05

246 Views

To enable the Azure VM accelerated settings using PowerShell, we need to enable the EnableAcceleratedNetworking property on the NIC attached to the VM.$vm = Get-AzVM -Name TestVM $nicname = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1] $nicsetting = Get-AzNetworkInterface -ResourceGroupName $vm.ResourceGroupName - Name $nicname $nicsetting.EnableAcceleratedNetworking = $trueIn the above example, we are setting AN settings on the Azure VM “TestVM”. To set the AN setting on the particular subscription, use the below command. Make sure that you are connected to the proper subscription using the Set-AzContext command.Get-AzVM | Select Name, ResourceGroupName, `    @{N='Accelerated Netoworking'; E={       $nic = (($_.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]       $nicsetting ... Read More

Advertisements