Skip to content

Instantly share code, notes, and snippets.

@FH-Inway
Created June 26, 2022 13:48
Show Gist options
  • Save FH-Inway/9140b17415c20147fef6eaaa633ad96c to your computer and use it in GitHub Desktop.
Save FH-Inway/9140b17415c20147fef6eaaa633ad96c to your computer and use it in GitHub Desktop.
d365fo.tools Az.Storage test
# Replace the following three variables with values for your own azure storage
$azureStorageAccountId = "miscfiles"
$sas = "sv2018-03-28&siunlisted&src&sigAUOpdsfpoWE976ASDhfjkasdf(5678sdfhk"
$container = "backupfiles"
$repositoryModulePath = ".\d365fo.tools"
$fileName = "Test.txt"
# Install d365fo.tools prerequisites
$modules = @("PSFramework", "PSScriptAnalyzer", "Az.Storage", "AzureAd", "PSNotification", "PSOAuthHelper", "ImportExcel")
foreach ($item in $modules) {
$module = Get-InstalledModule -Name $item -ErrorAction SilentlyContinue
if ($null -eq $module) {
Write-Host "Installing $item" -ForegroundColor Cyan
Install-Module -Name $item -Confirm:$false -Scope CurrentUser -SkipPublisherCheck -Verbose -Force
}
Import-Module $item -Verbose
}
# get d365fo.tools
cd C:\Temp
git clone https://github.com/FH-Inway/d365fo.tools.git
cd d365fo.tools
# switch to branch with changes for Az.Storage
git switch refactor-use-az.storage
# load module
Set-PSFConfig d365fo.tools.Import.IndividualFiles -Value $true
Set-PSFConfig d365fo.tools.Import.DoDotSource -Value $true
Import-Module -Name $repositoryModulePath -Force -Passthru -Verbose
# run tests
New-Item C:\Temp\$fileName
Set-Content C:\Temp\$fileName "d365fo.tools Az.Storage test"
Invoke-D365AzureStorageUpload -Verbose -AccountId $azureStorageAccountId -SAS $sas -Container $container -Filepath "c:\temp\$fileName" -Force -DeleteOnUpload
$file = Get-D365AzureStorageFile -Verbose -AccountId $azureStorageAccountId -SAS $sas -Container $container -Name $fileName
$file
Invoke-D365AzureStorageDownload -Verbose -AccountId $azureStorageAccountId -SAS $sas -Container $container -Name $fileName -Path "c:\temp"
Remove-Item C:\Temp\$fileName -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment