Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,25 @@ function Test-File
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].FileProperties.SmbProperties.FileAttributes.ToString()
}

Remove-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext
$fileName1 = "new" + $objectName1
$file = Get-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext

$file2 = Rename-AzStorageFile -ShareName $shareName -SourcePath $objectName1 -DestinationPath $fileName1 -Context $storageContext
Assert-AreEqual $file2.Name $fileName1
Assert-AreEqual $file.FileProperties.ContentType $file2.FileProperties.ContentType
Assert-AreEqual $file.FileProperties.ContentLength $file2.FileProperties.ContentLength

$file3 = $file2 | Rename-AzStorageFile -DestinationPath $fileName1 -Context $storageContext -Force
Assert-AreEqual $file3.Name $fileName1
Assert-AreEqual $file2.FileProperties.ContentType $file3.FileProperties.ContentType
Assert-AreEqual $file2.FileProperties.ContentLength $file3.FileProperties.ContentLength

Remove-AzStorageFile -ShareName $shareName -Path $fileName1 -Context $storageContext
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName2

$dirName = "filetestdir"
$dirName = "filetestdir"
New-AzStorageDirectory -ShareName $shareName -Path $dirName -Context $storageContext
$file = Get-AzStorageShare -Name $shareName -Context $storageContext | Get-AzStorageFile -ExcludeExtendedInfo
Assert-AreEqual $file.Count 2
Expand All @@ -125,11 +138,25 @@ function Test-File
Assert-AreEqual $file[1].Name $objectName2
Assert-AreEqual $file[1].GetType().Name "AzureStorageFile"
Assert-Null $file[1].ListFileProperties.Properties.ETag
Get-AzStorageFile -ShareName $shareName -Path $dirName -Context $storageContext | Remove-AzStorageDirectory

$newDir = "new" + $dirName
$dir = Get-AzStorageFile -ShareName $shareName -Path $dirName -Context $storageContext
$dir2 = Rename-AzStorageDirectory -ShareName $shareName -SourcePath $dirName -DestinationPath $newDir -Context $storageContext
Assert-AreEqual $newDir $dir2.Name
Assert-AreEqual $dir.ListFileProperties.IsDirectory $dir2.ListFileProperties.IsDirectory
Assert-AreEqual $dir.ListFileProperties.FileAttributes $dir2.ListFileProperties.FileAttributes

$newDir2 = "new2" + $dirName
$dir3 = $dir2 | Rename-AzStorageDirectory -DestinationPath $newDir2 -Context $storageContext
Assert-AreEqual $newDir2 $dir3.Name
Assert-AreEqual $dir2.ListFileProperties.IsDirectory $dir3.ListFileProperties.IsDirectory
Assert-AreEqual $dir2.ListFileProperties.FileAttributes $dir3.ListFileProperties.FileAttributes

$dir3 | Remove-AzStorageDirectory
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName2
Assert-AreEqual $file[0].GetType().Name "AzureStorageFile"
Assert-AreEqual $file[0].GetType().Name "AzureStorageFile"

# Clean Storage Account
Remove-AzStorageShare -Name $shareName -Force -Context $storageContext
Expand Down
3 changes: 2 additions & 1 deletion src/Storage/Storage.Management/Az.Storage.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ CmdletsToExport = 'Get-AzStorageAccount', 'Get-AzStorageAccountKey',
'New-AzStorageLocalUserSshPublicKey',
'New-AzStorageLocalUserPermissionScope',
'Get-AzDataLakeGen2DeletedItem',
'Restore-AzDataLakeGen2DeletedItem'
'Restore-AzDataLakeGen2DeletedItem',
'Rename-AzStorageFile', 'Rename-AzStorageDirectory'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Upcoming Release
* Supported rename file and directory
- `Rename-AzStorageFile`
- `Rename-AzStorageDirectory`
* Added a warning message for an upcoming breaking change when getting a single blob
- `Get-AzStorageBlob`
* Fixed the issue of listing blobs with leading slashes
Expand Down
259 changes: 259 additions & 0 deletions src/Storage/Storage.Management/help/Rename-AzStorageDirectory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.Storage.dll-Help.xml
Module Name: Az.Storage
online version: https://learn.microsoft.com/powershell/module/az.storage/rename-azstoragedirectory
schema: 2.0.0
---

# Rename-AzStorageDirectory

## SYNOPSIS
Renames a directory.

## SYNTAX

### ShareName
```
Rename-AzStorageDirectory [-ShareName] <String> [-SourcePath] <String> [[-DestinationPath] <String>]
[-Permission <String>] [-Force] [-AsJob] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-IgnoreReadonly] [<CommonParameters>]
```

### ShareObject
```
Rename-AzStorageDirectory [-ShareClient] <ShareClient> [-SourcePath] <String> [[-DestinationPath] <String>]
[-Permission <String>] [-Force] [-AsJob] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-IgnoreReadonly] [<CommonParameters>]
```

### DirecotryObject
```
Rename-AzStorageDirectory [-ShareDirectoryClient] <ShareDirectoryClient> [[-DestinationPath] <String>]
[-Permission <String>] [-Force] [-AsJob] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-IgnoreReadonly] [<CommonParameters>]
```

## DESCRIPTION
The **Rename-AzStorageDirectory** cmdlet renames a directory from a file share.

## EXAMPLES

### Example 1 : Rename a directory
```powershell
Rename-AzStorageDirectory -ShareName myshare -SourcePath testdir1 -DestinationPath testdir2
```

```output
Directory: https://myaccount.file.core.windows.net/myshare

Type Length Name
---- ------ ----
Directory 1 testdir2
```

This command renames a directory from testdir1 to testdir2.

### Example 2 : Rename a directory using pipeline
```powershell
Get-AzStorageFile -ShareName myshare -Path testdir1 | Rename-AzStorageDirectory -DestinationPath testdir2
```

```output
Directory: https://myaccount.file.core.windows.net/myshare

Type Length Name
---- ------ ----
Directory 1 testdir2
```

This command gets a directory from a file share first, and then rename the directory from testdir1 to testdir2 using pipeline.

## PARAMETERS

### -AsJob
Run cmdlet in the background

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Context
Azure Storage Context Object

```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzureRmContext, AzureCredential

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DestinationPath
The destination path to rename the directory to.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
Force to overwrite the existing file.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -IgnoreReadonly
Optional.
Specifies whether the ReadOnly attribute on a preexisting destination file should be respected.
If true, the rename will succeed, otherwise, a previous file at the destination with the ReadOnly attribute set will cause the rename to fail.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Permission
If specified the permission (security descriptor) shall be set for the directory/file.
Default value: Inherit.
If SDDL is specified as input, it must have owner, group and dacl.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ShareClient
ShareClienr indicated the share where the directory would be listed.

```yaml
Type: Azure.Storage.Files.Shares.ShareClient
Parameter Sets: ShareObject
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```

### -ShareDirectoryClient
Source directory instance

```yaml
Type: Azure.Storage.Files.Shares.ShareDirectoryClient
Parameter Sets: DirecotryObject
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```

### -ShareName
Name of the file share where the directory would be listed.

```yaml
Type: System.String
Parameter Sets: ShareName
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -SourcePath
Path to an existing directory.

```yaml
Type: System.String
Parameter Sets: ShareName, ShareObject
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### Azure.Storage.Files.Shares.ShareClient

### Azure.Storage.Files.Shares.ShareDirectoryClient

### Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext

## OUTPUTS

### Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory

## NOTES

## RELATED LINKS
Loading