Skip to content

Instantly share code, notes, and snippets.

View MauricioZa's full-sized avatar

Mauricio Zaragoza MauricioZa

View GitHub Profile
@MauricioZa
MauricioZa / JimKehoeFileExpiration.ps1
Created May 7, 2024 13:17
Jim Kehoe File Expiration
# -----------------------------------------------------------------------------
# Initialise
# -----------------------------------------------------------------------------
#region Init
$resourceGroupName = "rg-FileExpiration"
$location = "eastus"
$StorageAccountName = "pwcfileexpiration"
$shareName = "share"
$numberOfDays = -1
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.16.2.56959",
"templateHash": "14427937023370378081"
}
},
# ------------------------------
# Prerequisites:
# ------------------------------
# Install the Az module
# Create an Azure Resource Group in the desired subscription
# Create a virtual network in the desired resource group
# Create a subnet in the virtual network above
# -------------------------------------------
# Login to Azure and set the subscription:
# -------------------------------------
# Variables
# -------------------------------------
# Azure Subscription details
$StorageAccountName = "pbspszqarzcp001"
# Azure file share info
$letterAzure = "z:"
$uncPathAzure = "\\pbspszqarzcp001.file.core.windows.net\work"
# ---------------------------------------------------------------
# CONNECT TO AZURE
# ---------------------------------------------------------------
Connect-AzAccount
$SubscriptionId = "ef7f6efc-8813-4f2b-b1f0-71406ff5d7b4"
Select-AzSubscription -SubscriptionId $SubscriptionId
# ---------------------------------------------------------------
# VARIABLES
# Set Azure Storage context
$storageContext = New-AzStorageContext -StorageAccountName 'mystorageaccount' -StorageAccountKey "pleasInsertHereTheStorageAccountKey"
# Set source and destination containers
$containerName = 'container'
$newContainerName = 'newcontainer'
# Get all blobs in source container
$blobNames = Get-AzStorageBlob -Container $containername -Context $storageContext
# This script will create test local files in your on-premises file server.
# Later, you can use these files with robocopy to test the copy performance and network speed of your Azure Files setup.
# -----------------------------------------------------------------------
# Setup the directory where you want to create the dummy data
# -----------------------------------------------------------------------
##Dir creation
$Directory = "C:\dummy" ##Change as per requirement
New-Item -Path "$Directory\Large" -ItemType Directory
#------------------------------------------------------------
# Part A - Install necessary packages
#------------------------------------------------------------
# 1) Install DotNet (necessary for the AzFilesHybrid module) https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net472-web-installer
# 2) Download the AzFilesHybrid module zip file from: https://github.com/Azure-Samples/azure-files-samples/releases
# 3) Extract the file above to c:\temp
#------------------------------------------------------------
# Part A - Install necessary packages
#------------------------------------------------------------
# NOTE (Make sure the account you are using in windows is part of local administrators)
# 0) Download and unzip the One AD Active Roles Server cmdlets from : https://pwceur.sharepoint.com/:u:/r/sites/NisGlobalActiveDirectory/One%20AD%20Documents/Public/ARS%20Management%20Shell%207.4.4.zip
# 1) Install x86 and x64 Visual C++ redistrubutables from the (1.Redistributables) folder.
# 2) Install the x86 and x64 ADSI provider components from the (2. ActiveRoles ADSI Provider) folder.
# 3) Install the x86 and x64 ARS Management Shell components from the (3. ActiveRoles Management Shell) folder.
# Enter your Azure AD tenant ID. Replace with your own values.
$TenantId = "e65fxxxx-xxxx-xxxx-xxxx-aca6737299f3"
# Enter the path of the csv file to export users. Replace with your own values.
$csvPath = "C:\myfolder\users.csv"
# Set execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# OPTIONAL: Install modules (if you do not have them already installed)