Storage Account
You can install all these modules with a single aggregated module:
PS> Install-Module -Name Arcus.Scripting.Storage.All
- Blob storage
- Table storage
- File share
Installation
To have access to the following features, you have to import the module:
PS> Install-Module -Name Arcus.Scripting.Storage.Blob
Uploading files to a Azure Storage Blob container
Uploads a set of files located in a given directory to a container on a Azure Blob Storage resource.
| Parameter | Mandatory | Description |
|---|---|---|
ResourceGroupName | yes | The name of the Azure resource group where the Azure storage account is located. |
StorageAccountName | yes | The name of the Azure storage account. |
TargetFolderPath | yes | The directory where the files are located to upload to Azure Blob Storage. |
ContainerName | yes | The name of the container at Azure Blob Storage to upload the targeted files to. |
ContainerPermissions | no | The level of public access to this container. By default, the container and any blobs in it can be accessed only by the owner of the storage account. To grant anonymous users read permissions to a container and its blobs, you can set the container permissions to enable public access. Anonymous users can read blobs in a publicly available container without authenticating the request. The acceptable values for this parameter are: |
| Container: Provides full read access to a container and its blobs. Clients can enumerate blobs in the container through anonymous request, but cannot enumerate containers in the storage account. | ||
| Blob: Provides read access to blob data throughout a container through anonymous request, but does not provide access to container data. Clients cannot enumerate blobs in the container by using anonymous request. | ||
| Off: Which restricts access to only the storage account owner. | ||
FilePrefix | no | The optional prefix to append to the blob content when uploading the file in the targeted directory to Azure Blob Storage. |
Example
With existing blob container:
PS> Upload-AzFilesToBlobStorage `
-ResourceGroupName "resource-group" `
-StorageAccountName "account-name" `
-TargetFolderPath "./directory" `
-ContainerName "blob-container"
# Uploaded the file [file] to Azure Blob storage container: [Blob URL]
With non-existing blob container:
PS> Upload-AzFilesToBlobStorage `
-ResourceGroupName "resource-group" `
-StorageAccountName "account-name" `
-TargetFolderPath "./directory" `
-ContainerName "blob-container"
# Uploaded the file [file\ to Azure Blob storage container: [Blob URL]
Installation
To have access to the following features, you have to import the module:
PS> Install-Module -Name Arcus.Scripting.Storage.Table
Creating a new table in an Azure Storage Account
(Re)Create a Azure Table Storage within an Azure Storage Account.
| Parameter | Mandatory | Description |
|---|---|---|
ResourceGroupName | yes | The resource group where the Azure Storage Account is located |
StorageAccountName | yes | The name of the Azure Storage Account to add the table to |
TableName | yes | The name of the table to add on the Azure Storage Account |
Recreate | no | The optional flag to indicate whether or not a possible already existing table should be deleted and re-created |
RetryIntervalSeconds | no | The optional amount of seconds to wait each retry-run when a failure occurs during the re-creating process (default: 10s) |
MaxRetryCount | no | The optional maximum amount of retry-runs should happen when a failure occurs during the re-creating process (default: 10) |
Example
With non-existing table:
PS> Create-AzStorageTable `
-ResourceGroupName "stock" `
-StorageAccountName "admin" `
-TableName "products"
# Azure storage table 'products' does not exist yet in the Azure storage account 'admin', so will create one
# Azure storage table 'products' created in Azure storage account 'admin'
With existing table and re-create:
PS> Create-AzStorageTable `
-ResourceGroupName "stock" `
-StorageAccountName "admin" `
-TableName "products" `
-Recreate `
-RetryIntervalSeconds 3
# Azure storage table 'products' has been removed from Azure storage account 'admin'
# Failed to re-create the Azure storage table 'products' in Azure storage account 'admin', retrying in 3 seconds...
# Failed to re-create the Azure storage table 'products' in Azure storage account 'admin', retrying in 3 seconds...
# Azure storage table 'products' created in Azure storage account 'admin'
Set the entities in a table of an Azure Storage Account
Deletes all entities of a specified table in an Azure Storage Account and creates new entities based on a configuration file.
| Parameter | Mandatory | Description |
|---|---|---|
ResourceGroupName | yes | The resource group where the Azure Storage Account is located |
StorageAccountName | yes | The name of the Azure Storage Account that contains the table |
TableName | yes | The name of the table in which the entities should be set |
ConfigurationFile | yes | Path to the JSON Configuration file containing all the entities to be set |
Configuration File
The configuration file is a simple JSON file that contains all of the entities that should be set on the specified table, the JSON file consists of an array of JSON objects (= your entities). Each object contains simple name-value pairs (string-string).
Defining the PartitionKey and/or RowKey are optional, if not provided a random GUID will be set for these.
The file needs to adhere to the following JSON schema:
{
"definitions": {},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://scripting.arcus-azure.net/Features/powershell/azure-storage/azure-storage-table/config.json",
"type": "array",
"title": "The configuration JSON schema",
"items": [{
"type": "object",
"patternProperties": {
"^.*$": {
"anyOf": [{
"type": "string"
}, {
"type": "null"
}
]
}
},
"additionalProperties": false
}
]
}
Example Configuration File
[
{
"PartitionKey": "SystemA",
"RowKey": "100",
"ReadPath": "/home/in",
"ReadIntervalInSeconds": "30"
},
{
"PartitionKey": "SystemA",
"RowKey": "200",
"ReadPath": "/data/in",
"ReadIntervalInSeconds": "10",
"HasSubdirectories": "true"
}
]
Example
PS> Set-AzTableStorageEntities `
-ResourceGroupName "someresourcegroup" `
-StorageAccountName "somestorageaccount" `
-TableName "sometable" `
-ConfigurationFile ".\config.json"
# Deleting all existing entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup'...
# Successfully deleted all existing entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup'
# Successfully added all entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup'
Installation
To have access to the following features, you have to import the module:
PS> Install-Module -Name Arcus.Scripting.Storage.FileShare
Creating a folder on an Azure file share
Creates a new folder within the Azure File Share resource. When a folder already exists with the provided name, it will be skipped. No exception will be thrown.
| Parameter | Mandatory | Description |
|---|---|---|
ResourceGroupName | yes | The resource group containing the Azure File Share. |
StorageAccountName | yes | The Azure Storage Account name that hosting the Azure File Share. |
FileShareName | yes | The name of the Azure File Share. |
FolderName | yes | The name of the folder to create in the Azure File Share. |
Example
PS> Create-AzFileShareStorageFolder `
-ResourceGroupName "shipping-resources" `
-StorageAccountName "tracking-account-storage" `
-FileShareName "returned" -FolderName "containers"
# Created Azure FileShare storage folder 'containers' in file share 'returned'
Uploading files to a folder on an Azure file share
Upload a set of files from a given folder, optionally matching a specific file mask, to an Azure File Share.
| Parameter | Mandatory | Description |
|---|---|---|
ResourceGroupName | yes | The resource group containing the Azure File Share. |
StorageAccountName | yes | The name of the Azure Storage account that is hosting the Azure File Share. |
FileShareName | yes | The name of the Azure File Share. |
SourceFolderPath | yes | The file directory where the targeted files are located. |
DestinationFolderName | yes | The name of the destination folder on the Azure File Share where the targeted files will be uploaded. |
FileMask | no | The file mask that filters out the targeted files at the source folder that will be uploaded to the Azure File Share. |
Example
PS> Upload-AzFileShareStorageFiles `
-ResourceGroupName "shipping-resources" `
-StorageAccountName "tracking-account-storage" `
-FileShareName "returned" -SourceFolderPath "containers" `
-DestinationFolderName "containers"
# Uploaded the '[fileName]' file to Azure FileShare 'returned'
# Uploaded the '[fileName]' file to Azure FileShare 'returned'
# Files have been uploaded to Azure FileShare storage 'returned'