Reputation: 455
I want to delete all the files under an Azure data lake folder, and I am writing the following Powershell script to do it.
$tenantid = "xxxx-xxxxx-xxxxxxx-xxx"
$serviceprincipalid = "xxxx-xxxxxx-xxxxxxx-xxx"
$serviceprincipalkey = ConvertTo-SecureString "xxxxxxxxxxxxx" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($serviceprincipalid,$serviceprincipalkey)
$adlspath = "/Demo/"
$accountname = "testserv01"
Login-AzureRmAccount -Credential $psCred -TenantId $tenantid -ServicePrincipal
$AllFiles = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem];
$AllFiles = Get-AzureRmDataLakeStoreChildItem -AccountName $accountname -Path $adlspath
foreach($DelFiles in $AllFiles)
{
$delfilepath = $adlspath + $DelFiles.Name
Remove-AzureRmDataLakeStoreItem -AccountName $accountname -Paths $delfilepath -Force:$true
}
NOTE: I have masked certain values for security reason.
However, I am getting the following error while doing so:
$AllFiles = New-Object "System.Collections.Generic.List``1[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem]"
New-Object : Cannot find type [System.Collections.Generic.List`1[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem]]: make sure the assembly containing this type is loaded.
Upvotes: 0
Views: 487
Reputation: 4168
I see a bunch of posts where folks are running the code you've got. It looks like something happened between the version of AzureRM they used and what you're using now.
On a virgin Windows 10 system, I downloaded the AzureRM module...
Install-Module -Name AzureRM
Import-Module -Name AzureRM
Then I tried to run the offending line.
New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem]
And, I got the following.
New-Object : Cannot find type
[Collections.Generic.List[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem]]: verify that the assembly
containing this type is loaded.
At line:1 char:1
+ New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataLake ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
If I loaded the 4.2.1 AzureRM module...
Install-Module -Name AzureRM -RequiredVersion 4.2.1
Import-Module -Name AzureRM
Then I try the offending command, I don't get an error.
You have to dig a little deeper to see what changed, but as a quick and dirty fix, use an older version. Target the version of AzureRM around when the post with the code you're running was created.
Upvotes: 1