I have created a custom module as a PowerShell class following, roughly, the instructions available at Writing a custom DSC resource with PowerShell classes. The intent is to connect to Azure File Storage and download some files. I am using Azure Automation DSC as my pull server.
Let me start by saying that, when run through the PowerShell ISE, the code works a treat. Something goes wrong when I upload it to Azure though - I get the error Unable to find type [CloudFileDirectory]
. This type specifier comes from assemblies referenced in through the module Azure.Storage
which is definitely in my list of automation assets.
At the tippy top of my psm1
file I have
Using namespace Microsoft.WindowsAzure.Storage.File
[DscResource()]
class tAzureStorageFileSync
{
...
# Create the search context
[CloudFileDirectory] GetBlobRoot()
{
...
}
...
}
I'm not sure whether this Using
is supported in this scenario or not, so let's call that Question 1
To date I have tried:
- Adding
RequiredModules = @( "Azure.Storage" )
to thepsd1
file - Adding
RequiredAssemblies = @( "Microsoft.WindowsAzure.Storage.dll" )
to thepsd1
file - Shipping the actual
Microsoft.WindowsAzure.Storage.dll
file in the root of the module zip that I upload (that has a terrible smell about it)
When I deploy the module to Azure with New-AzureRmAutomationModule
it uploads and processes just fine. The Extracting activities...
step works and gives no errors.
When I compile a configuration, however, the compilation process fails with the Unable to find type
error I mentioned.
I have contemplated adding an Import-Module Azure.Storage
above the class
declaration, but I've never seen that done anywhere else before.
Question 2 Is there a way I can compile locally using a similar process to the one used by Azure DSC so I can test changes more quickly?
Question 3 Does anyone know what is going wrong here?