Skip to content

Instantly share code, notes, and snippets.

View using-statement.ps1
Function Using-Object(
[System.IDisposable]
$InputObject,
[scriptblock]
$ScriptBlock = {throw "ScriptBlock is mandatory, please provide a value."})
{
try
{
. $ScriptBlock
View Generate-Auth-Token.ps1
#This function generate auth token using azure sdk
Function GetAuthTokenUsingAzureSdk {
Param (
[Parameter(Mandatory)][ValidateNotNull()][ValidateNotNullOrEmpty()]
[String]$apiEndpointUri,
[Parameter(Mandatory)][ValidateNotNull()][ValidateNotNullOrEmpty()]
[String]$tenantId,
[Parameter(Mandatory)][ValidateNotNull()][ValidateNotNullOrEmpty()]
[String]$applicationId,
[Parameter(Mandatory)][ValidateNotNull()][ValidateNotNullOrEmpty()]
@jeevan90
jeevan90 / storage-account-out-connectionstring-withSAS.json
Created Jul 29, 2019
Create storage account and container and out put connection strings
View storage-account-out-connectionstring-withSAS.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"storageAccountApiVersion": "2018-07-01",
"storageAccountNameTidy": "[toLower(trim(parameters('storageAccountName')))]",
"blobEndPoint":"[concat('https://',variables('storageAccountNameTidy'),'.blob.core.windows.net/')]"
},
"parameters": {
"location": {
View arm-custom-function-usage.json
"resources": [
{
"name": "[parameters('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "[variables('storageAccountApiVersion')]",
"location": "[parameters('location')]",
"properties": {
"accessTier": "[parameters('accessTier')]",
"supportsHttpsTrafficOnly": "[parameters('supportsHttpsTrafficOnly')]"
},
View arm-template-function.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"functions": [
{
"namespace": "rt",
"members": {
"containerNameWithLocation": {
"parameters": [
{
@jeevan90
jeevan90 / copy-direcotry-recursive-msbuild.xml
Created Jul 25, 2019
Copy directory recursively in Ms Build
View copy-direcotry-recursive-msbuild.xml
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<CloudArtifacts Include=".Cloud\Data\**\*.*"/>
</ItemGroup>
<Target Name="CopyFiles">
<Copy SourceFiles="@(CloudArtifacts)" DestinationFiles="@(CloudArtifacts->'c:\PackableFiles\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
@jeevan90
jeevan90 / ServicePrinciplePowershell.ps1
Created Jul 15, 2019
Create Service Principal in Powershell and login to azure
View ServicePrinciplePowershell.ps1
#Create AD app
$dummyUrl = "https://dummy.dummy.com"
$passpowrd = "Qwerty@123!"
$securePassword = ConvertTo-SecureString -String $passpowrd -AsPlainText -Force
$app = New-AzureRmADApplication -DisplayName $dummyUrl `
-IdentifierUris $dummyUrl `
-HomePage $dummyUrl `
-Password $securePassword -Verbose
View LoginWithServicePrincipal.ps1
#Login with service principal
$clientId = "<CLIENT ID>"
$credentials = New-Object System.Management.Automation.PSCredential ($clientId, $securePassword)
Login-AzureRmAccount -ServicePrincipal -TenantId "<TENANTID>" `
-SubscriptionId "<SUBSCRIPTIONID>" `
-Credential $credentials
View CreateServicePrincipal.ps1
#Create Service principal
New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId `
-DisplayName $dummyUrl `
-Password $securePassword `
-Scope "/subscriptions/<SUBSCRIPTION ID>" `
-Role Contributor `
-StartDate ([datetime]::Now) `
-EndDate $([datetime]::now.AddYears(1)) -Verbose
View CreateADApp.ps1
#Create AD app
$dummyUrl = "https://dummy.dummy.com"
$passpowrd = "Qwerty@123!"
$securePassword = ConvertTo-SecureString -String $passpowrd -AsPlainText -Force
$app = New-AzureRmADApplication -DisplayName $dummyUrl `
-IdentifierUris $dummyUrl `
-HomePage $dummyUrl `
-Password $securePassword -Verbose