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.
Related
I'm trying to create a new JSON deployment file from an existing object.. but the new object wont allow me to add additional parameters
Export-AzResourceGroup -ResourceGroupName $InputObject.ResourceGroupName -Resource $InputObject.id -IncludeParameterDefaultValue -IncludeComments -Path ./InputObject.json
$NewObject=Get-Content -Raw ./InputObject.json | ConvertFrom-Json
$NewObject.resources.zones={1,2,3}
#InvalidOperation: The property 'zones' cannot be found on this object. Verify that the property exists and can be set.
$newObject.resources.Add('zones')
MethodInvocationException: Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."
How to add additional resource entries into the array?
(goal is to export an existing AppGateway, delete it and recreate it with zone redundancy)
Check Types of the items you get .
See <<Object>>.GetType() , System.Collections.Hashtable , Add-Member and System.Collections.Generic.List[object] .
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
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…..”.
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.