About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Flagged Code Snippets
($response.content | ConvertFrom-Json).runId
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelines/Adfv2QuickStartParamPipeline?api-version=${apiVersion}"
$body = @"
{
"name": "Adfv2QuickStartParamPipeline",
"properties": {
"activities": [
{
"name": "CopyFromBlobToBlob",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "BinarySource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": true
}
},
"sink": {
"type": "BinarySink",
"storeSettings": {
"type": "AzureBlobStorageWriteSettings"
}
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "ParamInputDataset",
"type": "DatasetReference",
"parameters": {
"strInputFileName": {
"value": "@pipeline().parameters.strParamInputFileName",
"type": "Expression"
}
}
}
],
"outputs": [
{
"referenceName": "ParamOutputDataset",
"type": "DatasetReference",
"parameters": {
"strOutPutFileName": {
"value": "@pipeline().parameters.strParamOutputFileName",
"type": "Expression"
}
}
}
]
}
],
"parameters": {
"strParamInputFileName": {
"type": "String"
},
"strParamOutputFileName": {
"type": "String"
}
}
}
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
Select-AzSubscription -SubscriptionId "<SubscriptionId>"
$tenantID = "<your tenant ID>"
$appId = "<your application ID>"
$clientSecrets = "<your clientSecrets for the application>"
$subscriptionId = "<your subscription ID to create the factory>"
$resourceGroupName = "<your resource group to create the factory>"
$factoryName = "<specify the name of data factory to create. It must be globally unique.>"
$apiVersion = "2018-06-01"
$credentials = Get-Credential -UserName $appId
Connect-AzAccount -ServicePrincipal -Credential $credentials -Tenant $tenantID
Remove-AzResourceGroup -ResourceGroupName $resourcegroupname
$body = @"
{
"location": "East US",
"properties": {},
"identity": {
"type": "SystemAssigned"
}
}
"@
$response = Invoke-AzRestMethod -SubscriptionId ${subscriptionId} -ResourceGroupName ${resourceGroupName} -ResourceProviderName Microsoft.DataFactory -ResourceType "factories" -Name ${factoryName} -ApiVersion ${apiVersion} -Method PUT -Payload ${body}
$response.Content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/linkedservices/AzureStorageLinkedService?api-version=${apiVersion}"
$body = @"
{
"name":"AzureStorageLinkedService",
"properties":{
"annotations":[
],
"type":"AzureBlobStorage",
"typeProperties":{
"connectionString":"DefaultEndpointsProtocol=https;AccountName=<accountName>;AccountKey=<accountKey>"
}
}
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/datasets/InputDataset?api-version=${apiVersion}"
$body = @"
{
"name":"InputDataset",
"properties":{
"linkedServiceName":{
"referenceName":"AzureStorageLinkedService",
"type":"LinkedServiceReference"
},
"annotations":[
],
"type":"Binary",
"typeProperties":{
"location":{
"type":"AzureBlobStorageLocation",
"fileName":"emp.txt",
"folderPath":"input",
"container":"adftutorial"
}
}
}
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/datasets/OutputDataset?api-version=${apiVersion}"
$body = @"
{
"name":"OutputDataset",
"properties":{
"linkedServiceName":{
"referenceName":"AzureStorageLinkedService",
"type":"LinkedServiceReference"
},
"annotations":[
],
"type":"Binary",
"typeProperties":{
"location":{
"type":"AzureBlobStorageLocation",
"folderPath":"output",
"container":"adftutorial"
}
}
}
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelines/Adfv2QuickStartPipeline?api-version=${apiVersion}"
$body = @"
{
"name": "Adfv2QuickStartPipeline",
"properties": {
"activities": [
{
"name": "CopyFromBlobToBlob",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "BinarySource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": true
}
},
"sink": {
"type": "BinarySink",
"storeSettings": {
"type": "AzureBlobStorageWriteSettings"
}
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "InputDataset",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "OutputDataset",
"type": "DatasetReference"
}
]
}
],
"annotations": []
}
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelines/Adfv2QuickStartPipeline/createRun?api-version=${apiVersion}"
$response = Invoke-AzRestMethod -Path ${path} -Method POST
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/datasets/ParamInputDataset?api-version=${apiVersion}"
$body = @"
{
"name": "ParamInputDataset",
"properties": {
"linkedServiceName": {
"referenceName": "AzureStorageLinkedService",
"type": "LinkedServiceReference"
},
"parameters": {
"strInputFileName": {
"type": "string"
}
},
"annotations": [],
"type": "Binary",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"fileName": {
"value": "@dataset().strInputFileName",
"type": "Expression"
},
"folderPath": "input",
"container": "adftutorial"
}
}
},
"type": "Microsoft.DataFactory/factories/datasets"
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/datasets/ParamOutputDataset?api-version=${apiVersion}"
$body = @"
{
"name": "ParamOutputDataset",
"properties": {
"linkedServiceName": {
"referenceName": "AzureStorageLinkedService",
"type": "LinkedServiceReference"
},
"parameters": {
"strOutPutFileName": {
"type": "string"
}
},
"annotations": [],
"type": "Binary",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"fileName": {
"value": "@dataset().strOutPutFileName",
"type": "Expression"
},
"folderPath": "output",
"container": "adftutorial"
}
}
},
"type": "Microsoft.DataFactory/factories/datasets"
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method PUT -Payload $body
$response.content
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelines/Adfv2QuickStartParamPipeline/createRun?api-version=${apiVersion}"
$body = @"
{
"strParamInputFileName": "emp2.txt",
"strParamOutputFileName": "aloha.txt"
}
"@
$response = Invoke-AzRestMethod -Path ${path} -Method POST -Payload $body
$response.content
$runId = ($response.content | ConvertFrom-Json).runId
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelineruns/${runId}?api-version=${apiVersion}"
while ($True) {
$response = Invoke-AzRestMethod -Path ${path} -Method GET
$response = $response.content | ConvertFrom-Json
Write-Host "Pipeline run status: " $response.Status -foregroundcolor "Yellow"
if ( ($response.Status -eq "InProgress") -or ($response.Status -eq "Queued") -or ($response.Status -eq "In Progress") ) {
Start-Sleep -Seconds 10
}
else {
$response | ConvertTo-Json
break
}
}
$path = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataFactory/factories/${factoryName}/pipelineruns/${runId}/queryActivityruns?api-version=${apiVersion}"
while ($True) {
$response = Invoke-AzRestMethod -Path ${path} -Method POST
$responseContent = $response.content | ConvertFrom-Json
$responseContentValue = $responseContent.value
Write-Host "Activity run status: " $responseContentValue.Status -foregroundcolor "Yellow"
if ( ($responseContentValue.Status -eq "InProgress") -or ($responseContentValue.Status -eq "Queued") -or ($responseContentValue.Status -eq "In Progress") ) {
Start-Sleep -Seconds 10
}
else {
$responseContentValue | ConvertTo-Json
break
}
}
Remove-AzDataFactoryV2 -Name "<NameOfYourDataFactory>" -ResourceGroupName "<NameOfResourceGroup>"