Not able to upload video asset file from powershell to Azure Media service

Category: azure media services


Ashok Padarthi on Thu, 10 Nov 2016 09:50:57

Hi Team,

I am trying to upload video to media service using powershell i have used following steps and script to perform the operation but uploading failing with exception "Exception calling "Upload" with "1" argument(s): "One or more errors occurred."

I have downloaded Media services from nuget "windowsazure.mediaservices."

Script used

$storageAccountName="testmediasvcstorage" #Classic Storage account
$location="West Europe"
New-AzureMediaServicesAccount -Name $mediaServiceAccountName -Location $location -StorageAccountName $storageAccountName
$mediaService=Get-AzureMediaServicesAccount $mediaServiceAccountName

Add-Type -Path D:\w\dev\SYC_NuGet\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll;
Add-Type -Path D:\w\dev\SYC_NuGet\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll;
Add-Type -Path D:\w\dev\SYC_NuGet\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll;
Add-Type -Path D:\w\dev\SYC_NuGet\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll;
Add-Type -Path D:\w\dev\SYC_NuGet\packages\TransientFaultHandling.Core.5.1.1209.1\lib\NET4\Microsoft.Practices.TransientFaultHandling.Core.dll;
Add-Type -Path D:\w\dev\SYC_NuGet\packages\windowsazure.mediaservices.\lib\net45\Microsoft.WindowsAzure.MediaServices.Client.dll;

$CloudMediaContext = New-Object -TypeName Microsoft.WindowsAzure.MediaServices.Client.CloudMediaContext -ArgumentList $mediaService.Name, $mediaService.MediaServicesPrimaryAccountKey;
$Asset = @{
Name = 'TestAsset';
FileList = @(
Name = 'test.wmv';
Source = '{0}\test.wmv' -f "D:\Logpath";
# Create a new Asset (maps to storage container)
if (!($NewAsset = $CloudMediaContext.Assets.Where({ $PSItem.Name -eq $Asset.Name}))) {
Write-Verbose -Message ('Creating new asset named: {0}' -f $Asset.Name);
$NewAsset = $CloudMediaContext.Assets.Create($Asset.Name, [Microsoft.WindowsAzure.MediaServices.Client.AssetCreationOptions]::CommonEncryptionProtected);
# Upload all files to Asset
foreach ($File in $Asset.FileList) {
# If the file name already exists as an Azure Asset File, then skip it
if (@($NewAsset.AssetFiles).Where({ $PSItem.Name -eq $File.Name; })) {
Write-Verbose -Message ('File {0} already exists in asset {1}' -f $File.Name, $NewAsset.Name);
continue; };
Write-Verbose -Message ('Uploading file {0} to asset {1}' -f $File.Name, $Asset.Name);
# Create a new Azure Asset File
$NewFile = $NewAsset.AssetFiles.Create($File.Name);
# Upload the local file to the Azure Asset File
$NewFile.Upload($File.Source) # Execption thrown here
$NewFile = $null;
$ErrorMessage = $_.Exception.Message  
Write-Host $ErrorMessage

Please help me getting it resolved.