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 @@ -56,6 +56,7 @@ function Test-File
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName1
Assert-NotNull $file[0].ListFileProperties.Properties.ETag

if ($Env:OS -eq "Windows_NT")
{
Expand All @@ -65,16 +66,17 @@ function Test-File
{
Set-AzStorageFileContent -source $localSrcFile -ShareName $shareName -Path $objectName1 -Force -Context $storageContext
}
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName1
Assert-NotNull $file[0].ListFileProperties.Properties.ETag
if ($Env:OS -eq "Windows_NT")
{
$file[0].CloudFile.FetchAttributes()
$localFileProperties = Get-ItemProperty $localSrcFile
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].CloudFile.Properties.CreationTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].CloudFile.Properties.LastWriteTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].CloudFile.Properties.NtfsAttributes.ToString()
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].ListFileProperties.Properties.CreatedOn.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].ListFileProperties.Properties.LastWrittenOn.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].ListFileProperties.FileAttributes.ToString()
}

Start-AzStorageFileCopy -SrcShareName $shareName -SrcFilePath $objectName1 -DestShareName $shareName -DestFilePath $objectName2 -Force -Context $storageContext -DestContext $storageContext
Expand Down Expand Up @@ -103,9 +105,9 @@ function Test-File
{
$file = Get-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext
$localFileProperties = Get-ItemProperty $localSrcFile
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].CloudFile.Properties.CreationTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].CloudFile.Properties.LastWriteTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].CloudFile.Properties.NtfsAttributes.ToString()
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].FileProperties.SmbProperties.FileCreatedOn.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].FileProperties.SmbProperties.FileLastWrittenOn.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].FileProperties.SmbProperties.FileAttributes.ToString()
}

Remove-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext
Expand All @@ -115,12 +117,14 @@ function Test-File

$dirName = "filetestdir"
New-AzStorageDirectory -ShareName $shareName -Path $dirName -Context $storageContext
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
$file = Get-AzStorageShare -Name $shareName -Context $storageContext | Get-AzStorageFile -ExcludeExtendedInfo
Assert-AreEqual $file.Count 2
Assert-AreEqual $file[0].Name $objectName2
Assert-AreEqual $file[0].GetType().Name "AzureStorageFile"
Assert-AreEqual $file[1].Name $dirName
Assert-AreEqual $file[1].GetType().Name "AzureStorageFileDirectory"
Assert-AreEqual $file[0].Name $dirName
Assert-AreEqual $file[0].GetType().Name "AzureStorageFileDirectory"
Assert-Null $file[0].ListFileProperties.Properties.ETag
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
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.9.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.9.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.9.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.10.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.10.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.10.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="24.0.0" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
## Upcoming Release
* Show OAuth token in debug log in debug build only
- `New-AzStorageContext`
* Supported return more file properties when list Azure file
- `Get-AzStorageFile`

## Version 4.5.0
* Supported DaysAfterLastTierChangeGreaterThan in Management Policy
Expand Down
33 changes: 24 additions & 9 deletions src/Storage/Storage.Management/help/Get-AzStorageFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ Lists directories and files for a path.

### ShareName (Default)
```
Get-AzStorageFile [-ShareName] <String> [[-Path] <String>] [-Context <IStorageContext>]
Get-AzStorageFile [-ShareName] <String> [[-Path] <String>] [-ExcludeExtendedInfo] [-Context <IStorageContext>]
[-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [<CommonParameters>]
```

### Share
```
Get-AzStorageFile [-Share] <CloudFileShare> [[-Path] <String>] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[<CommonParameters>]
Get-AzStorageFile [-Share] <CloudFileShare> [[-Path] <String>] [-ExcludeExtendedInfo]
[-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [<CommonParameters>]
```

### Directory
```
Get-AzStorageFile [-Directory] <CloudFileDirectory> [[-Path] <String>] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[<CommonParameters>]
Get-AzStorageFile [-Directory] <CloudFileDirectory> [[-Path] <String>] [-ExcludeExtendedInfo]
[-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -102,7 +102,7 @@ To obtain a Storage context, use the New-AzStorageContext cmdlet.

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

Required: False
Expand Down Expand Up @@ -145,6 +145,21 @@ Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```

### -ExcludeExtendedInfo
Not include extended file info like timestamps, ETag, attributes, permissionKey in list file and Directory.

```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
```

### -Path
Specifies the path of a folder.
If you omit the *Path* parameter, **Get-AzStorageFile** lists the directories and files in the specified file share or directory.
Expand Down Expand Up @@ -214,7 +229,7 @@ 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).
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

Expand Down
85 changes: 76 additions & 9 deletions src/Storage/Storage/Common/AzureStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
using global::Azure.Storage.Files.Shares;
using global::Azure.Storage;
using Microsoft.WindowsAzure.Commands.Storage.Common;
using global::Azure.Storage.Files.Shares.Models;
using Microsoft.Azure.Storage.Auth;

/// <summary>
/// Azure storage file object
/// </summary>
public class AzureStorageFile : AzureStorageBase
{
/// <summary>
/// CloudBlob object
/// File object
/// </summary>
[Ps1Xml(Label = "Share Uri", Target = ViewControl.Table, GroupByThis = true, ScriptBlock = "$_.CloudFile.Share.Uri")]
[Ps1Xml(Label = "Name", Target = ViewControl.Table, ScriptBlock = "$_.Name", Position = 0, TableColumnWidth = 20)]
public CloudFile CloudFile { get; private set; }

/// <summary>
/// Blob length
/// File length
/// </summary>
[Ps1Xml(Label = "Length", Target = ViewControl.Table, Position = 1, TableColumnWidth = 15)]
public long Length { get; private set; }
Expand All @@ -56,7 +58,7 @@ public ShareFileClient ShareFileClient
{
if (privateFileClient == null)
{
privateFileClient = GetTrack2FileClient(this.CloudFile, (AzureStorageContext)this.Context);
privateFileClient = GetTrack2FileClient(this.CloudFile, this.shareClientOptions);
}
return privateFileClient;
}
Expand All @@ -80,20 +82,85 @@ public ShareFileClient ShareFileClient
private global::Azure.Storage.Files.Shares.Models.ShareFileProperties privateFileProperties = null;

/// <summary>
/// Azure storage file constructor
/// XSCL Track2 File List properties
/// </summary>
public global::Azure.Storage.Files.Shares.Models.ShareFileItem ListFileProperties { get; private set; }


private ShareClientOptions shareClientOptions { get; set; }

/// <summary>
/// Azure storage file constructor from track1 file object
/// </summary>
/// <param name="file">Cloud file object</param>
public AzureStorageFile(CloudFile file, AzureStorageContext storageContext)
public AzureStorageFile(CloudFile file, AzureStorageContext storageContext, ShareClientOptions clientOptions = null)
{
Name = file.Name;
CloudFile = file;
Length = file.Properties.Length;
LastModified = file.Properties.LastModified;
Context = storageContext;
shareClientOptions = clientOptions;
}

/// <summary>
/// Azure storage file constructor from Track2 list file item
/// </summary>
/// <param name="file">Cloud file object</param>
public AzureStorageFile(ShareFileClient shareFileClient, AzureStorageContext storageContext, ShareFileItem shareFileItem, ShareClientOptions clientOptions = null)
{
Name = shareFileClient.Name;
this.privateFileClient = shareFileClient;
CloudFile = GetTrack1FileClient(shareFileClient, storageContext.StorageAccount.Credentials);
if (shareFileItem != null)
{
ListFileProperties = shareFileItem;
if (shareFileItem.FileSize != null)
{
Length = shareFileItem.FileSize.Value;
}
if (shareFileItem.Properties != null)
{
LastModified = shareFileItem.Properties.LastModified;
}
}
Context = storageContext;
shareClientOptions = clientOptions;
}

/// <summary>
/// Azure storage file constructor from Track2 get file properties output
/// </summary>
/// <param name="file">Cloud file object</param>
public AzureStorageFile(ShareFileClient shareFileClient, AzureStorageContext storageContext, ShareFileProperties shareFileProperties = null, ShareClientOptions clientOptions = null)
{
Name = shareFileClient.Name;
this.privateFileClient = shareFileClient;
CloudFile = GetTrack1FileClient(shareFileClient, storageContext.StorageAccount.Credentials);
if (shareFileProperties != null)
{
privateFileProperties = shareFileProperties;
Length = shareFileProperties.ContentLength;
LastModified = shareFileProperties.LastModified;
}
Context = storageContext;
shareClientOptions = clientOptions;
}

// Convert Track2 File object to Track 1 file object
public static CloudFile GetTrack1FileClient(ShareFileClient shareFileClient, StorageCredentials credentials)
{
if (credentials.IsSAS) // the Uri already contains credentail.
{
credentials = null;
}
CloudFile track1CloudFile;
track1CloudFile = new CloudFile(shareFileClient.Uri, credentials);
return track1CloudFile;
}

// Convert Track1 File object to Track 2 file Client
public static ShareFileClient GetTrack2FileClient(CloudFile cloudFile, AzureStorageContext context)
public static ShareFileClient GetTrack2FileClient(CloudFile cloudFile, ShareClientOptions clientOptions = null)
{
ShareFileClient fileClient;
if (cloudFile.ServiceClient.Credentials.IsSAS) //SAS
Expand All @@ -109,16 +176,16 @@ public static ShareFileClient GetTrack2FileClient(CloudFile cloudFile, AzureStor
{
fullUri = fullUri + "?" + sas;
}
fileClient = new ShareFileClient(new Uri(fullUri));
fileClient = new ShareFileClient(new Uri(fullUri), clientOptions);
}
else if (cloudFile.ServiceClient.Credentials.IsSharedKey) //Shared Key
{
fileClient = new ShareFileClient(cloudFile.SnapshotQualifiedUri,
new StorageSharedKeyCredential(context.StorageAccountName, cloudFile.ServiceClient.Credentials.ExportBase64EncodedKey()));
new StorageSharedKeyCredential(cloudFile.ServiceClient.Credentials.AccountName, cloudFile.ServiceClient.Credentials.ExportBase64EncodedKey()), clientOptions);
}
else //Anonymous
{
fileClient = new ShareFileClient(cloudFile.SnapshotQualifiedUri);
fileClient = new ShareFileClient(cloudFile.SnapshotQualifiedUri, clientOptions);
}

return fileClient;
Expand Down
Loading