This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$FolderName = "C:\Temp1" | |
$DestinationPath = "C:\Temp2" | |
$Dates = Get-ChildItem -Path $FolderName -ErrorAction SilentlyContinue | Select-Object -Property @{Name = "CreationTime"; Expression = { $_.CreationTime.Date } } -Unique | |
$Files = Get-ChildItem -Path $FolderName -ErrorAction SilentlyContinue | |
foreach ($Dt in $Dates.CreationTime) { $Files | Where-Object { $_.CreationTime.Date -eq $Dt } | Compress-Archive -DestinationPath "$DestinationPath\$($Dt.ToString("MMM_yyyy")).zip" -Force } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## On the NEW VM in which User Assigned Managed Identity enabled | |
# Enter-PSSession -ComputerName $vmPIP -Credential $credential | |
# Install NuGet package provider where Az module is availble | |
Install-PackageProvider -Name NuGet -Force | |
# Install the Az module | |
Install-Module -Name Az -Force | |
# Login to Azure with managed identity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the public ip of the new VM | |
$vmPIP = Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $vmName | % IpAddress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assign the identity and enable User Assigned Managed Identity on Virtual Machine. | |
$null = Update-AzVM -ResourceGroupName $rgName -VM $vm ` | |
-IdentityType UserAssigned -IdentityID $identity.Id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grant GET permissions to secrets on Key Key Vault to managed identity | |
Set-AzKeyVaultAccessPolicy -ResourceGroupName $rgName -VaultName $keyVaultName ` | |
-ServicePrincipalName $identity.ClientId -PermissionsToSecrets get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grant Reader role to Managed Identity on Key Vault | |
$null = New-AzRoleAssignment -ApplicationId $identity.ClientId ` | |
-RoleDefinitionName Reader -Scope $keyVault.ResourceId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a secret to Key Vault | |
$null = Set-AzKeyVaultSecret -VaultName $keyVaultName ` | |
-Name $userName -SecretValue $securePassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Azure Key Vault | |
$keyVaultName = 'testakv99' | |
$keyVault = New-AzKeyVault -ResourceGroupName $rgName ` | |
-Name $keyVaultName -Location $location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install and Import the module | |
$moduleName = 'Az.ManagedServiceIdentity' | |
Install-Module -Name $moduleName -Force | |
Import-Module -Name $moduleName | |
# Create User Assugned Managed Identity | |
$identityName = 'amuai' | |
$identity = New-AzUserAssignedIdentity -Name $identityName ` | |
-ResourceGroupName $rgName -Location $location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a Resource Group | |
$rgName = 'Test-RG' | |
$location = 'westus' | |
$null = New-AzResourceGroup -Name $rgName -Location $location | |
# Create a Virtual Machine | |
$vmName = 'Test-VM' | |
$userName = 'sysadmin' | |
$plainTextPassword = 'P@ssw0rd!' | |
$securePassword = $plainTextPassword | ConvertTo-SecureString -AsPlainText -Force |