Skip to content

Commit 9d2c29e

Browse files
authored
Merge pull request #109582 from normesta/normesta-sdk-interop
updates based on latest release
2 parents 98fe800 + 4eadd44 commit 9d2c29e

File tree

1 file changed

+67
-108
lines changed

1 file changed

+67
-108
lines changed

articles/storage/blobs/data-lake-storage-directory-file-acl-powershell.md

Lines changed: 67 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: normesta
66
ms.service: storage
77
ms.subservice: data-lake-storage-gen2
88
ms.topic: conceptual
9-
ms.date: 12/13/2019
9+
ms.date: 03/30/2020
1010
ms.author: normesta
1111
ms.reviewer: prishet
1212
---
@@ -30,27 +30,27 @@ This article shows you how to use PowerShell to create and manage directories, f
3030
3131
## Install PowerShell modules
3232

33-
1. Verify that the version of PowerShell that have installed is `5.1` or higher by using the following command.
33+
1. Verify that the version of PowerShell that have installed is `5.1` or higher by using the following command.
3434

35-
```powershell
36-
echo $PSVersionTable.PSVersion.ToString()
37-
```
35+
```powershell
36+
echo $PSVersionTable.PSVersion.ToString()
37+
```
3838

39-
To upgrade your version of PowerShell, see [Upgrading existing Windows PowerShell](https://docs.microsoft.com/powershell/scripting/install/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell)
39+
To upgrade your version of PowerShell, see [Upgrading existing Windows PowerShell](https://docs.microsoft.com/powershell/scripting/install/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell)
4040

41-
2. Install the latest **PowershellGet** module. Then, close and reopen the Powershell console.
41+
2. Install the latest **PowershellGet** module. Then, close and reopen the PowerShell console.
4242

43-
```powershell
44-
install-Module PowerShellGet –Repository PSGallery –Force
45-
```
43+
```powershell
44+
install-Module PowerShellGet –Repository PSGallery –Force
45+
```
4646

47-
3. Install **Az.Storage** preview module.
47+
3. Install **Az.Storage** preview module.
4848

49-
```powershell
50-
install-Module Az.Storage -Repository PSGallery -RequiredVersion 1.9.1-preview –AllowPrerelease –AllowClobber Force
51-
```
49+
```powershell
50+
Install-Module az.storage -RequiredVersion 1.13.3-preview -Repository PSGallery -AllowClobber -AllowPrerelease -Force
51+
```
5252

53-
For more information about how to install PowerShell modules, see [Install the Azure PowerShell module](https://docs.microsoft.com/powershell/azure/install-az-ps?view=azps-3.0.0)
53+
For more information about how to install PowerShell modules, see [Install the Azure PowerShell module](https://docs.microsoft.com/powershell/azure/install-az-ps?view=azps-3.0.0)
5454

5555
## Connect to the account
5656

@@ -124,10 +124,10 @@ $dirname = "my-directory/"
124124
$dir = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname
125125
$dir.ACL
126126
$dir.Permissions
127-
$dir.Directory.PathProperties.Group
128-
$dir.Directory.PathProperties.Owner
129-
$dir.Directory.Metadata
130-
$dir.Directory.Properties
127+
$dir.Group
128+
$dir.Owner
129+
$dir.Metadata
130+
$dir.Properties
131131
```
132132

133133
## Rename or move a directory
@@ -143,13 +143,16 @@ $dirname2 = "my-new-directory/"
143143
Move-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -DestFileSystem $filesystemName -DestPath $dirname2
144144
```
145145

146+
> [!NOTE]
147+
> Use the `-Force` parameter if you want to overwrite without prompts.
148+
146149
This example moves a directory named `my-directory` to a subdirectory of `my-directory-2` named `my-subdirectory`. This example also applies a umask to the subdirectory.
147150

148151
```powershell
149152
$filesystemName = "my-file-system"
150153
$dirname = "my-directory/"
151154
$dirname2 = "my-directory-2/my-subdirectory/"
152-
Move-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname1 -DestFileSystem $filesystemName -DestPath $dirname2 -Umask --------x -PathRenameMode Posix
155+
Move-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname1 -DestFileSystem $filesystemName -DestPath $dirname2
153156
```
154157

155158
## Delete a directory
@@ -181,24 +184,24 @@ Get-AzDataLakeGen2ItemContent -Context $ctx -FileSystem $filesystemName -Path $f
181184

182185
## List directory contents
183186

184-
List the contents of a directory by using the `Get-AzDataLakeGen2ChildItem` cmdlet.
187+
List the contents of a directory by using the `Get-AzDataLakeGen2ChildItem` cmdlet. You can use the optional parameter `-OutputUserPrincipalName` to get the name (instead of the object ID) of users.
185188

186189
This example lists the contents of a directory named `my-directory`.
187190

188191
```powershell
189192
$filesystemName = "my-file-system"
190193
$dirname = "my-directory/"
191-
Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Path $dirname
194+
Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Path $dirname -OutputUserPrincipalName
192195
```
193196

194-
This example doesn't return values for the `ACL`, `Permissions`, `Group`, and `Owner` properties. To obtain those values, use the `-FetchPermission` parameter.
197+
This example doesn't return values for the `ACL`, `Permissions`, `Group`, and `Owner` properties. To obtain those values, use the `-FetchProperty` parameter.
195198

196-
The following example lists the contents of the same directory, but it also uses the `-FetchPermission` parameter to return values for the `ACL`, `Permissions`, `Group`, and `Owner` properties.
199+
The following example lists the contents of the same directory, but it also uses the `-FetchProperty` parameter to return values for the `ACL`, `Permissions`, `Group`, and `Owner` properties.
197200

198201
```powershell
199202
$filesystemName = "my-file-system"
200203
$dirname = "my-directory/"
201-
$properties = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Path $dirname -Recurse -FetchPermission
204+
$properties = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Path $dirname -Recurse -FetchProperty
202205
$properties.ACL
203206
$properties.Permissions
204207
$properties.Group
@@ -241,10 +244,10 @@ $file = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $
241244
$file
242245
$file.ACL
243246
$file.Permissions
244-
$file.File.PathProperties.Group
245-
$file.File.PathProperties.Owner
246-
$file.File.Metadata
247-
$file.File.Properties
247+
$file.Group
248+
$file.Owner
249+
$file.Metadata
250+
$file.Properties
248251
```
249252

250253
## Delete a file
@@ -263,15 +266,24 @@ You can use the `-Force` parameter to remove the file without a prompt.
263266

264267
## Manage access permissions
265268

266-
You can get, set, and update access permissions of directories and files.
269+
You can get, set, and update access permissions of file systems, directories and files.
267270

268271
> [!NOTE]
269272
> If you're using Azure Active Directory (Azure AD) to authorize commands, then make sure that your security principal has been assigned the [Storage Blob Data Owner role](https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#storage-blob-data-owner). To learn more about how ACL permissions are applied and the effects of changing them, see [Access control in Azure Data Lake Storage Gen2](https://docs.microsoft.com/azure/storage/blobs/data-lake-storage-access-control).
270273
271-
### Get directory and file permissions
274+
### Get permissions
272275

273276
Get the ACL of a directory or file by using the `Get-AzDataLakeGen2Item`cmdlet.
274277

278+
279+
This example gets the ACL of a **file system** and then prints the ACL to the console.
280+
281+
```powershell
282+
$filesystemName = "my-file-system"
283+
$filesystem = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName
284+
$filesystem.ACL
285+
```
286+
275287
This example gets the ACL of a **directory**, and then prints the ACL to the console.
276288

277289
```powershell
@@ -295,18 +307,30 @@ The following image shows the output after getting the ACL of a directory.
295307

296308
In this example, the owning user has read, write, and execute permissions. The owning group has only read and execute permissions. For more information about access control lists, see [Access control in Azure Data Lake Storage Gen2](data-lake-storage-access-control.md).
297309

298-
### Set directory and file permissions
310+
### Set or update permissions
299311

300-
Use the `New-AzDataLakeGen2ItemAclObject` cmdlet to create an ACL for the owning user, owning group, or other users. Then, use the `Update-AzDataLakeGen2Item` cmdlet to commit the ACL.
312+
Use the `set-AzDataLakeGen2ItemAclObject` cmdlet to create an ACL for the owning user, owning group, or other users. Then, use the `Update-AzDataLakeGen2Item` cmdlet to commit the ACL.
313+
314+
This example sets the ACL on a **file system** for the owning user, owning group, or other users, and then prints the ACL to the console.
315+
316+
```powershell
317+
$filesystemName = "my-file-system"
318+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
319+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
320+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission -wx -InputObject $acl
321+
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Acl $acl
322+
$filesystem = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname
323+
$filesystem.ACL
324+
```
301325

302326
This example sets the ACL on a **directory** for the owning user, owning group, or other users, and then prints the ACL to the console.
303327

304328
```powershell
305329
$filesystemName = "my-file-system"
306330
$dirname = "my-directory/"
307-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
308-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
309-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
331+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
332+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
333+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission -wx -InputObject $acl
310334
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -Acl $acl
311335
$dir = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname
312336
$dir.ACL
@@ -316,9 +340,9 @@ This example sets the ACL on a **file** for the owning user, owning group, or ot
316340
```powershell
317341
$filesystemName = "my-file-system"
318342
$filePath = "my-directory/upload.txt"
319-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
320-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
321-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
343+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
344+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
345+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
322346
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $filePath -Acl $acl
323347
$file = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $filePath
324348
$file.ACL
@@ -330,82 +354,17 @@ The following image shows the output after setting the ACL of a file.
330354

331355
In this example, the owning user and owning group have only read and write permissions. All other users have write and execute permissions. For more information about access control lists, see [Access control in Azure Data Lake Storage Gen2](data-lake-storage-access-control.md).
332356

333-
### Update directory and file permissions
334-
335-
Use the `Get-AzDataLakeGen2Item` cmdlet to get the ACL of a directory or file. Then, use the `New-AzDataLakeGen2ItemAclObject` cmdlet to create a new ACL entry. Use the `Update-AzDataLakeGen2Item` cmdlet to apply the new ACL.
336-
337-
This example gives a group write and execute permission on a directory.
338-
339-
```powershell
340-
$filesystemName = "my-file-system"
341-
$dirname = "my-directory/"
342-
$Id = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
343-
344-
# Get the directory ACL
345-
$acl = (Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname).ACL
346-
347-
# Create the new ACL object.
348-
[Collections.Generic.List[System.Object]]$aclnew =$acl
349-
350-
# To avoid duplicate ACL, remove the ACL entries that will be added later.
351-
foreach ($a in $aclnew)
352-
{
353-
if ($a.AccessControlType -eq "group" -and $a.DefaultScope -eq $true-and $a.EntityId -eq $id)
354-
{
355-
$aclnew.Remove($a);
356-
break;
357-
}
358-
}
359-
360-
# Add ACL Entries
361-
$aclnew = New-AzDataLakeGen2ItemAclObject -AccessControlType group -EntityId $id -Permission "-wx" -DefaultScope -InputObject $aclnew
362-
363-
# Update ACL on server
364-
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -Acl $aclnew
365-
366-
```
367-
368-
This example gives a group write and execute permission on a file.
369-
370-
```powershell
371-
$filesystemName = "my-file-system"
372-
$fileName = "my-directory/upload.txt"
373-
$Id = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
374-
375-
# Get the file ACL
376-
$acl = (Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $fileName).ACL
377-
378-
# Create the new ACL object.
379-
[Collections.Generic.List[System.Object]]$aclnew =$acl
380-
381-
# To avoid duplicate ACL, remove the ACL entries that will be added later.
382-
foreach ($a in $aclnew)
383-
{
384-
if ($a.AccessControlType -eq "group" -and $a.DefaultScope -eq $true-and $a.EntityId -eq $id)
385-
{
386-
$aclnew.Remove($a);
387-
break;
388-
}
389-
}
390-
391-
# Add ACL Entries
392-
$aclnew = New-AzDataLakeGen2ItemAclObject -AccessControlType group -EntityId $id -Permission "-wx" -DefaultScope -InputObject $aclnew
393-
394-
# Update ACL on server
395-
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $fileName -Acl $aclnew
396-
397-
```
398357

399358
### Set permissions on all items in a file system
400359

401360
You can use the `Get-AzDataLakeGen2Item` and the `-Recurse` parameter together with the `Update-AzDataLakeGen2Item` cmdlet to recursively to set the ACL of all directories and files in a file system.
402361

403362
```powershell
404363
$filesystemName = "my-file-system"
405-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
406-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
407-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
408-
Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Recurse -FetchPermission | Update-AzDataLakeGen2Item -Acl $acl
364+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
365+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
366+
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission -wx -InputObject $acl
367+
Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName -Recurse -FetchProperty | Update-AzDataLakeGen2Item -Acl $acl
409368
```
410369
<a id="gen1-gen2-map" />
411370

0 commit comments

Comments
 (0)