0

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.
1
  • I don't see you adding the type anywhere in your code. Commented Jul 29, 2018 at 20:42

1 Answer 1

1

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.

enter image description here

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.