Having issues adding Azure Virtual Applications
We're trying to add azure virtual applications within our CI/CD pipeline via referencing a powershell script (This is within Azure DevOps' product). I've built a container with all the underlying framework, which I've been testing on. However, this part is borking the entire process, and we can't seem to make headway on a resolution or workaround.
First attempt:
$ArrayList = New-Object -TypeName System.Collections.ArrayList `
>> $ArrayList.Add((Add-Type -AssemblyName Microsoft.Azure.Management.WebSites.Models.VirtualApplication("/Customer", "si
te\wwwroot\Customer")))
Error:
Add-Type : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:2 char:17
+ ... ayList.Add((Add-Type -AssemblyName Microsoft.Azure.Management.WebSite ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Type], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.AddTypeCommand
$ArrayList.Add((Add-Type -TypeName Microsoft.Azure.Management.WebSites.Models.VirtualApplication("/Customer", "site\wwwroot\Customer")))
Second direction:
Error:
Add-Type : A parameter cannot be found that matches parameter name 'TypeName'.
At line:2 char:26
+ $ArrayList.Add((Add-Type -TypeName Microsoft.Azure.Management.WebSite ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Type], ParameterBindingExce
ption
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.
AddTypeCommand
Add-Type cmdlet takes types in the specified assembly, this cmdlet does not have return value. You need to call New-Object cmdlet to instantiate the types.
You can check the official documents for more information
Below scripts is only for reference:
Add-Type –AssemblyName Microsoft.Azure.Management.WebSites
$VA = New-Object -TypeName Microsoft.Azure.Management.WebSites.Models.VirtualApplication -ArgumentList ("/Customer", "si
te\wwwroot\Customer")
$ArrayList.Add($VA)
Add-Type cmdlet does not work on my powershell for some reason. Instead I add the assembly using [Reflection.Assembly]::LoadFrom(path to assembly.dll). You can use [Reflection.Assembly]::LoadFrom() if add-type throws error ‘Unable to load…..”.
Related
I need to create multiple azure monitor alarms.
I'm trying to do this following this website:
https://www.azureblue.io/how-to-create-an-alert-rule-using-powershell-and-azure-cli/
This solution works for me if I have action group and target resources in the same subscription but generally I don't.
I have one actiongroup and hundreds targets in almost 100 subscriptions.
I have:
#jump to subscription with actiongroup
$context = Get-AzSubscription -SubscriptionId xxx
Set-AzContext $context
$actionGroup = Get-AzActionGroup -name "xxx" -ResourceGroupName "xxx"
$actionGroupId = New-AzActionGroup -ActionGroupId $actionGroup.Id
#jump to subscription with target without this I can't ask for target.id
$context = Get-AzSubscription -SubscriptionId xx
Set-AzContext $context
# Creates a local criteria object that can be used to create a new metric alert
$condition = New-AzMetricAlertRuleV2Criteria `
-MetricName "Data space used percent (Platform)" `
-TimeAggregation Maximum `
-Operator GreaterThan `
-Threshold 0.8
$windowSize = New-TimeSpan -Minutes 30
$frequency = New-TimeSpan -Minutes 5
$targetResourceId = (Get-AzResource -Name xxx).Id
#I was thinking that this jump to subscription will solve my issue but doesn't
$context = Get-AzSubscription -SubscriptionId cf653672-c304-49a2-b01b-171f6236bad6
Set-AzContext $context
# Adds or updates a V2 (non-classic) metric-based alert rule.
Add-AzMetricAlertRuleV2 `
-Name "test" `
-ResourceGroupName "xxx" `
-WindowSize $windowSize `
-Frequency $frequency `
-TargetResourceId $targetResourceId `
-Condition $condition `
-ActionGroup $actionGroupId `
-Severity 3
I got this error:
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:NotFound, Reason phrase: Not Found
At line:26 char:1
+ Add-AzMetricAlertRuleV2 `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzMetricAlertRuleV2], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmMetricAlertRuleV2Command
From GUI there is no a problem to chose actiongroup from different subscription but you can't chose targets from multiple subscription.
If I will find solution for this one example I will try to read all my resources and run the code in a loop.
I had an error like that recently.. It was due to an invalid input. In my particular case it was due to invalid characters in the alertName.
As for the main issue of multiple subscriptions...
Here are a couple of ideas:
To apply an single metric alert to multiple resources of the same type as the same time. You can specify scope, region etc with Add-AzMetricAlertRuleV2 see:
https://learn.microsoft.com/en-us/powershell/module/az.monitor/add-azmetricalertrulev2?view=azps-7.2.0. This is limited to only a few resources https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-metric-overview#monitoring-at-scale-using-metric-alerts-in-azure-monitor.
Note that TargetResourceScope is a array of strings. So it seems possible in theory to apply the alert to multiple subscriptions with this.
When other option are not possible: use Get-AzSubscription, and deploy the code to each subscription or to get the list of subscriptions you need to run the code with.
Your single action group.
I can validate that, you can have a single action group for any alerts inside a subscription. I don't see any reason why the the action group could not be in a separate subscription provided the actiongroup.id is correct and there are no RBAC/firewall issues. But I don't have a way to test this.
Lastly, here is a relevant conversation in an MS forum. https://techcommunity.microsoft.com/t5/azure-monitor/azure-monitor-multiple-subscriptions/m-p/1348362
I have a paid and free integration account setup on Azure. I have already generated a few partners and agreements using the portal with no issues. Im now looking to use some powershell scripts to help control the creation of these partners and agreements in the future.
When trying to build script to create a partner I hit this bottleneck with the business identities.
New-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Invalid business identity.
$ResourceGroupName = 'rg-test'
$IntegrationAccountName = 'inter-test'
$PartnerName = 'TestPartner'
$BusinessIdentities = #{
Qualifier = "AS2Identity"
Value = "TestIdentity"
}
New-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName -Name $IntegrationAccountName -PartnerName $PartnerName -BusinessIdentities $BusinessIdentities
Reference: https://learn.microsoft.com/en-us/powershell/module/az.logicapp/new-azintegrationaccountpartner?view=azps-4.6.1
Is there something Im unaware when it comes to hash-tables?
Powershell Core MacOS 10.15.6
Major Minor Patch PreReleaseLabel BuildLabel
7 0 3
Update:
Adding Resolve-AzError Response.
HistoryId: 4
Message : Invalid business identity.
StackTrace : at Microsoft.Azure.Commands.LogicApp.Utilities.CmdletHelper.ConvertToBusinessIdentityList(Object businessIdentityObject)
at Microsoft.Azure.Commands.LogicApp.Cmdlets.NewAzureIntegrationAccountPartnerCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Management.Automation.PSArgumentException
InvocationInfo : {New-AzIntegrationAccountPartner}
Line : New-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName -Name $IntegrationAccountName -PartnerName $PartnerName -BusinessIdentities
$BusinessIdentities
Position : At /Users/john/Desktop/run.ps1:10 char:1
+ New-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 4
According to my research, when we run the command New-AzIntegrationAccountPartner, we need to define BusinessIdentities as Array. Becase the code Microsoft.Azure.Commands.LogicApp.Utilities.CmdletHelper.ConvertToBusinessIdentityList(Object businessIdentityObject) in the command New-AzIntegrationAccountPartner need users to provide Array object. Otherwise, it will throw error. For more details, please refer to here and here.
For example
$ResourceGroupName = 'testaks'
$IntegrationAccountName = 'test06'
$PartnerName = 'TestPartner'
$BusinessIdentities = #("<the Qualifier's value such as AS2Identity>","<The Value's value>")
New-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName -Name $IntegrationAccountName -PartnerName $PartnerName -BusinessIdentities $BusinessIdentities
I am trying to Create a Private DNS zone by specifying virtual network IDs with Powershell, and my command goes as follows,
New-AzDnsZone -Name 'dnszone01' -ResourceGroupName 'thisRG' -ZoneType 'Private' -RegistrationVirtualNetworkId #($vnet.Id)
I am getting an error as,
New-AzDnsZone : The zone name 'dnszone01' does not have enough labels.
Zone names must have two or more labels. At line:1 char:1
+ New-AzDnsZone -Name 'dnszone01' -ResourceGroupName 'thisRG' -Zon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzDnsZone], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Dns.NewAzureDnsZone
what am I missing here?
The dns name must be fully qualifed. for example:
dnszone1.local
dnszone.mysite.com
Add .azure.com to the name:
Example -
resource "azurerm_private_dns_zone" "dnszone" {
name = "${var.private_dns_zone_name}-pdz.postgres.database.azure.com"
resource_group_name = var.resource_group_name
I am following the blog, to fetch usage details for my subscription.
https://blogs.technet.microsoft.com/keithmayer/2015/06/30/export-azure-subscription-usage-to-csv-with-new-billing-api-and-powershell/
"Export Azure Usage via PowerShell using Get-UsageAggregates" (part 1)
I am getting the below error:
Get-UsageAggregates : InvalidInput: Parameter continuationtoken was missing or had an unacceptable value.
At line:30 char:18
+ ... usageData = Get-UsageAggregates -ReportedStartTime $reportedStartTime ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-UsageAggregates], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.UsageAggregates.GetUsageAggregatesCommand
If anyone has worked around this, please let me know how to solve this?
I replaced "" with $null and it seems to be working for the continuationToken.
I'm trying to do something very simple, but with being new to powershell I'm having trouble figuring out what is wrong:
PS C:\Windows\system32> $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
New-Object : Cannot find type [[System.IO.Directory]::CreateDirectory]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
try just:
$directoryMaker = [System.IO.Directory]::CreateDirectory("C:\test")
In this case you are using a static method ( CreateDirectory(string s) ) of the [System.IO.Directory] then you don't need to instantiate a [System.IO.Directory] object to reference the new folder created by this method itself.