fixed Get-Exception cmdlet invocation

This commit is contained in:
Jorge Cotillo 2019-08-17 22:16:16 -07:00
Родитель b98130c5cc
Коммит 546f201162
6 изменённых файлов: 73 добавлений и 105 удалений

Просмотреть файл

@ -265,10 +265,9 @@
] ]
}, },
{ {
"name": "[concat('nestedDeploymentUM-Win',variables('tagPatching')[copyindex()].name)]", "name": "[concat(parameters('automationAccountName'), '/windows-um-',subscription().displayName,'-',variables('tagPatching')[copyindex()].name)]",
"type": "Microsoft.Resources/deployments", "type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
"comments": "Using nested deployment because a nested resource cannot have a copy function", "apiVersion": "2017-05-15-preview",
"apiVersion": "2017-05-10",
"copy": { "copy": {
"count": "[length(variables('tagPatching'))]", "count": "[length(variables('tagPatching'))]",
"name": "patchingWinTagLoop" "name": "patchingWinTagLoop"
@ -276,18 +275,6 @@
"dependsOn": [ "dependsOn": [
"[parameters('automationAccountName')]" "[parameters('automationAccountName')]"
], ],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[concat(parameters('automationAccountName'), '/windows-um-',subscription().displayName,'-',variables('tagPatching')[copyindex()].name)]",
"type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
"apiVersion": "2017-05-15-preview",
"properties": { "properties": {
"updateConfiguration": { "updateConfiguration": {
"operatingSystem": "Windows", "operatingSystem": "Windows",
@ -317,36 +304,18 @@
}, },
"scheduleInfo": "[variables('tagPatching')[copyindex()].schedule]" "scheduleInfo": "[variables('tagPatching')[copyindex()].schedule]"
} }
}
]
}
}
}, },
{ {
"name": "[concat('nestedDeploymentUM-Linux',variables('tagPatching')[copyindex()].name)]", "name": "[concat(parameters('automationAccountName'), '/linux-um-',subscription().displayName,'-',variables('tagPatching')[copyindex()].name)]",
"type": "Microsoft.Resources/deployments", "type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
"comments": "Using nested deployment because a nested resource cannot have a copy function", "apiVersion": "2017-05-15-preview",
"apiVersion": "2017-05-10",
"copy": { "copy": {
"count": "[length(variables('tagPatching'))]", "count": "[length(variables('tagPatching'))]",
"name": "patchingLinuxTagLoop" "name": "patchingLinuxTagLoop"
}, },
"dependsOn": [ "dependsOn": [
"[parameters('automationAccountName')]",
"patchingWinTagLoop" "patchingWinTagLoop"
], ],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[concat(parameters('automationAccountName'), '/linux-um-',subscription().displayName,'-',variables('tagPatching')[copyindex()].name)]",
"type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
"apiVersion": "2017-05-15-preview",
"properties": { "properties": {
"updateConfiguration": { "updateConfiguration": {
"operatingSystem": "Linux", "operatingSystem": "Linux",
@ -377,10 +346,6 @@
"scheduleInfo": "[variables('tagPatching')[copyindex()].schedule]" "scheduleInfo": "[variables('tagPatching')[copyindex()].schedule]"
} }
} }
]
}
}
}
], ],
"outputs": { "outputs": {
"automationAccountResourceId": { "automationAccountResourceId": {

Просмотреть файл

@ -356,12 +356,12 @@ Function Get-Exception {
elseif($errorObject -is [System.Management.Automation.ErrorRecord] ` elseif($errorObject -is [System.Management.Automation.ErrorRecord] `
-and $null -ne $errorObject.Exception) { -and $null -ne $errorObject.Exception) {
return ` return `
GetException $errorObject.Exception; Get-Exception $errorObject.Exception;
} }
elseif($errorObject -is [System.Exception] ` elseif($errorObject -is [System.Exception] `
-and $null -ne $errorObject.ErrorRecord) { -and $null -ne $errorObject.ErrorRecord) {
return ` return `
GetException $errorObject.ErrorRecord; Get-Exception $errorObject.ErrorRecord;
} }
else { else {
return $errorObject.Message; return $errorObject.Message;

Просмотреть файл

@ -83,7 +83,7 @@ Class ModuleStateDataService: IModuleStateDataService {
# If deploymentMapping is null, it means that there is no mapping found # If deploymentMapping is null, it means that there is no mapping found
if (!$deploymentMapping) { if (!$deploymentMapping) {
Write-Host "No state information found"; Write-Debug "No state information found";
return $null; return $null;
} }
else { else {
@ -92,7 +92,7 @@ Class ModuleStateDataService: IModuleStateDataService {
$deploymentMapping.DeploymentName, $deploymentMapping.DeploymentName,
$deploymentMapping.StateId $deploymentMapping.StateId
); );
Write-Host "Filters: $(ConvertTo-Json $filters)"; Write-Debug "Filters: $(ConvertTo-Json $filters)";
$resourceState = ` $resourceState = `
$this.stateRepository.GetResourceStateByFilters($filters); $this.stateRepository.GetResourceStateByFilters($filters);

Просмотреть файл

@ -548,10 +548,13 @@ Class AzureResourceManagerDeploymentService: IDeploymentService {
# Adding comma in between array items # Adding comma in between array items
$formattedResourceIds = $allResourceIds -join ","; $formattedResourceIds = $allResourceIds -join ",";
Write-Debug "Query to execute is: where id in ($formattedResourceIds)";
$resourceStates = ` $resourceStates = `
Start-ExponentialBackoff ` Start-ExponentialBackoff `
-Expression { Search-AzGraph -Query "where id in ($formattedResourceIds)"; } -Expression { Search-AzGraph -Query "where id in ($formattedResourceIds)"; }
Write-Debug "Resource states from Resource Graph: $(ConvertTo-Json $resourceStates -Depth 10)"
$dataToReturn.ResourceStates = $resourceStates; $dataToReturn.ResourceStates = $resourceStates;
# Let's retrieve deployment outputs # Let's retrieve deployment outputs

Просмотреть файл

@ -57,7 +57,7 @@ Class BlobContainerAuditRepository: IAuditRepository {
$temporalFileName = [Guid]::NewGuid(); $temporalFileName = [Guid]::NewGuid();
$temporalFilePath = ` $temporalFilePath = `
Join-Path $this.temporalRootPath "$temporalFileName.json" Join-Path $this.temporalRootPath "$temporalFileName.json"
Write-Host "TemporalFilePath is: $temporalFilePath"; Write-Debug "TemporalFilePath is: $temporalFilePath";
try { try {
# Let's create the file contents temporally # Let's create the file contents temporally
@ -121,7 +121,7 @@ Class BlobContainerAuditRepository: IAuditRepository {
$this.mappingsBlobContainerName, $this.mappingsBlobContainerName,
$blobName); $blobName);
Write-Host "Container name: $($this.mappingsBlobContainerName) and blob name: $blobName"; Write-Debug "Container name: $($this.mappingsBlobContainerName) and blob name: $blobName";
# Set the initial value equals to the # Set the initial value equals to the
# mappingsContent from above, this allows # mappingsContent from above, this allows
@ -287,7 +287,7 @@ Class BlobContainerAuditRepository: IAuditRepository {
$temporalFileName = [Guid]::NewGuid(); $temporalFileName = [Guid]::NewGuid();
$temporalFilePath = ` $temporalFilePath = `
Join-Path $this.temporalRootPath "$temporalFileName.json"; Join-Path $this.temporalRootPath "$temporalFileName.json";
Write-Host "Temporal File Path is $temporalFilePath"; Write-Debug "Temporal File Path is $temporalFilePath";
try { try {
$blobFound = Get-AzStorageBlobContent ` $blobFound = Get-AzStorageBlobContent `
@ -298,14 +298,14 @@ Class BlobContainerAuditRepository: IAuditRepository {
-ErrorAction SilentlyContinue; -ErrorAction SilentlyContinue;
if ($blobFound -eq $null) { if ($blobFound -eq $null) {
Write-Host "Blob not found"; Write-Debug "Blob not found. Blob: $blob, Container: $container";
return ""; return "";
} }
else { else {
$contentJson = ` $contentJson = `
Get-Content $temporalFilePath ` Get-Content $temporalFilePath `
-Raw; -Raw;
Write-Host "Content Json is $contentJson"; Write-Debug "Content Json is $contentJson";
return $contentJson; return $contentJson;
} }
} }

Просмотреть файл

@ -127,7 +127,7 @@ Class BlobContainerStateRepository: IStateRepository {
$blobExists = $this.BlobExists( $blobExists = $this.BlobExists(
$this.mappingsBlobContainerName, $this.mappingsBlobContainerName,
$blobName); $blobName);
Write-Host "Container name: $($this.mappingsBlobContainerName) and blob name: $blobName"; Write-Debug "Container name: $($this.mappingsBlobContainerName) and blob name: $blobName";
# Set the initial value equals to the # Set the initial value equals to the
# mappingsContent from above, this allows # mappingsContent from above, this allows
# us to save the initial contents when a # us to save the initial contents when a
@ -228,7 +228,7 @@ Class BlobContainerStateRepository: IStateRepository {
$this.stateBlobContainerName, $this.stateBlobContainerName,
$blobName); $blobName);
Write-Host "Blob container: $($this.stateBlobContainerName), Blob Name: $blobName"; Write-Debug "Blob container: $($this.stateBlobContainerName), Blob Name: $blobName";
# A non-empty value indicates that a blob exists # A non-empty value indicates that a blob exists
if (![string]::IsNullOrEmpty($blobFound)) { if (![string]::IsNullOrEmpty($blobFound)) {
@ -270,12 +270,12 @@ Class BlobContainerStateRepository: IStateRepository {
$filters[0]; $filters[0];
$moduleInstanceName = ` $moduleInstanceName = `
$filters[1]; $filters[1];
Write-Host "archetypeInstanceName: $archetypeInstanceName, moduleInstanceName: $moduleInstanceName"; Write-Debug "archetypeInstanceName: $archetypeInstanceName, moduleInstanceName: $moduleInstanceName";
$blobName = $this.mappingsBlobPath -F ` $blobName = $this.mappingsBlobPath -F `
$archetypeInstanceName; $archetypeInstanceName;
Write-Host "Blob container: $($this.mappingsBlobContainerName), Blob Name: $blobName"; Write-Debug "Blob container: $($this.mappingsBlobContainerName), Blob Name: $blobName";
# Let's check if the blob exists, if it does, # Let's check if the blob exists, if it does,
# this function will return the blob contents # this function will return the blob contents