Found 463 Articles for PowerShell

How to retrieve the OS caching setting of Azure VM using AzureCLI in PowerShell?

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

112 Views

To retrieve the OS Caching setting of the Azure VM using CLI, we can use the below command.PS C:\> az vm show -n VMName -g VMRG --query storageProfile.osDisk.caching -otsvOutputReadWriteYou can also get the caching setting on the Azure VM without using the resource group name using the command below.PS C:\> az vm list --query "[?name=='vmname'].storageProfile.osDisk.caching" -otsvIf you need to retrieve the setting for all VMs then,PS C:\> az vm list --query "[].{VMName:name, ResourceGroup:resourceGroup, caching:storageProfile.osDisk.caching}" -otable

How to retrieve the OS of the Azure VM using Azure CLI in PowerShell?

Chirag Nagrekar
Updated on 02-Sep-2021 10:59:25

1K+ Views

To retrieve the Azure VM OS using Azure CLI, we can use the “az vm” command but before that, need to make sure that you are connected to the Azure cloud and the subscription.PS C:\> az vm show -n VMName -g VMRG --query "[storageProfile.imageReference.offer]" -otsvORPS C:\> az vm show -n VMName -g VMRG --query storageProfile.imageReference.offer - otsvOutputWindowsServerTo get the OS SKU or the operating system version, you can use, PS C:\> az vm show -n VMName -g VMRG --query "[storageProfile.imageReference.sku]" -otsvOutput2016-DatacenterYou can also use the below command to get the OS of the VM without providing the resource group name.PS C:\> ... Read More

How to resolve - Relative path is not supported in PowerShell DSC?

Chirag Nagrekar
Updated on 01-Sep-2021 08:35:58

440 Views

“Relative path is not supported” error generally occurs with the PowerShell DSC when we download a file from online or Website and we use “File” DscResource for that.In the below example, we are downloading the PowerShell 7.1.4 version from GitHub using DSC to the local computer and we get the error below.ExampleConfiguration FileCopy{    Node LocalHost{       File CopyFromBlob{          SourcePath = "https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x86.msi"          DestinationPath = "C:\Temp\"          Ensure = 'Present'       }    } } FileCopy -OutputPath C:\Temp\dsc\FileCopy Start-DscConfiguration -Path C:\Temp\dsc\FileCopy -Wait -ForceOutputRelative path is ... Read More

How to install DSC resources using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:21:55

447 Views

To install the DSC resource using PowerShell, we can use the same command to install modules in PowerShell (Install-Module).The Find-DscResource command would get all the available DSC resources. To search the specific DSC resource, you can provide the -Name parameter in the Find-DscReource command. For example, we need to search for the FilesAndFolder DSC resourceFind-DSCResource -Name filesandfoldersOutputName             Version ModuleName Repository ----             ------- ---------- ---------- FilesAndFolders 0.3.212 CommonTasks PSGalleryTo install this module, we can pipeline the Install-Module command.Find-DSCResource -Name filesandfolders | Install-Module -Force -VerboseOnce the module is installed, we can ... Read More

How to generate multiple reports in HTML using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 08:18:57

431 Views

To generate or append multiple outputs in the HTML file using PowerShell, we need to use the - Fragment parameter in the ConvertTo-HTML command.For example, let say we need to generate the computer utilization report which includes the top 5 consuming processes, stopped services, and the disk utilization report. A single report can be generated by sending the output to the ConvertTo-HTML pipeline command.Example$Heading = "System Utilization Report" $procs = Get-Process | Sort-Object -Property CPU -Descending| Select - First 5 | `    ConvertTo-Html -Property ProcessName, ID, CPU -Fragment - PreContent "High Utilization Processes" $services = Get-Service | ... Read More

How to generate an HTML report using PowerShell?

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

4K+ 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

3K+ 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

1K+ 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 enable soft delete for Azure Storage blobs using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 09:01:11

378 Views

To enable soft delete for Azure Storage blobs in Storage account properties using PowerShell, we can use the Enable-AzureStorageDeleteRetentionPolicy command. From the Azure portal, we need to access the Data Protection property of the Azure Storage account.You can also provide the retention days to keep the soft-deleted data. To perform the same with the Azure PowerShell we need to use the Enable-AzureStorageDeleteRetentionPolicy command. Before running this command you need to make sure that you are connected to the Azure Cloud account (if not then use Connect-AzAccount) and the proper azure subscription (if not then use Set-AzContext) command.To use the Enable-AzureStorageDeleteRetentionPolicy you ... Read More

Advertisements