New-AzResource

This Azure PowerShell article will discuss the syntax and usage of the New-AzResource Azure PowerShell cmdlet with implementation examples.

New-AzResource

New-AzResource is an excellent Azure PowerShell cmdlet that can help you quickly create an Azure resource like a website or an Azure SQL database/server in a resource group.

Syntax:

Below is the syntax of the New-AzResource Azure PowerShell cmdlet.

New-AzResource
   [-Location <String>]
   [-Properties <PSObject>]
   -ResourceName <String>
   -ResourceType <String>
   [-ResourceGroupName <String>]
   [-Force]

   [<CommonParameters>]

Well, let’s discuss a few examples of how to use the New-AzResource Azure PowerShell cmdlet.

Example-1:

You can execute the Azure PowerShell cmdlet below to create a TsInfoweb website in MyNewResGrp Resource Group.

New-AzResource -Location "east US" -Properties @{demo="demo"} -ResourceName TsInfoweb -ResourceType microsoft.web/sites -ResourceGroupName MyNewResGrp -Force

After executing the above Azure PowerShell cmdlet, You can see below the website was created successfully, and I got the below output.

PS C:\WINDOWS\system32> New-AzResource -Location "east US" -Properties @{demo="demo"} -ResourceName TsInfoweb -ResourceType microsoft.web/sites -ResourceGroupName MyNewResGrp -Force


Name              : TsInfoweb
ResourceId        : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups
                    /MyNewResGrp/providers/Microsoft.Web/sites/TsInfoweb
ResourceName      : TsInfoweb
ResourceType      : Microsoft.Web/sites
Kind              : app
ResourceGroupName : MyNewResGrp
Location          : east US
SubscriptionId    : 1cdf4300-dee5-4518-8c8c-feaa72a5kid1
Properties        : @{name=TsInfoweb; state=Running; hostNames=System.Object[]; 
                    webSpace=MyNewResGrp-EastUSwebspace; selfLink=https://waws-prod-bl
                    u-399.api.azurewebsites.windows.net:454/subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5kid1/webspaces/MyNewResGrp-EastUSwebspace/site
                    s/TsInfoweb; repositorySiteName=TsInfoweb; owner=; 
                    usageState=Normal; enabled=True; adminEnabled=True; 
                    enabledHostNames=System.Object[]; siteProperties=; 
                    availabilityState=Normal; sslCertificates=; csrs=System.Object[]; 
                    cers=; siteMode=; hostNameSslStates=System.Object[]; 
                    computeMode=; serverFarm=; serverFarmId=/subscriptions/1cdf4300-de
        1cdf4300-dee5-4518-8c8c-feaa72a5kid1/resourceGroups/MyNewResGrp/providers/Mic
                    rosoft.Web/serverfarms/Default1ph; reserved=False; isXenon=False; 
                    hyperV=False; lastModifiedTimeUtc=2023-04-11T07:05:39.3933333; 
                    storageRecoveryDefaultState=Running; 
                    contentAvailabilityState=Normal; runtimeAvailabilityState=Normal; 
                    dnsConfiguration=; vnetRouteAllEnabled=False; 
                    containerAllocationSubnet=; useContainerLocalhostBindings=; 
                    vnetImagePullEnabled=False; vnetContentShareEnabled=False; 
                    siteConfig=; deploymentId=TsInfoweb; slotName=; 
                    trafficManagerHostNames=; sku=Free; scmSiteAlsoStopped=False; 
                    targetSwapSlot=; hostingEnvironment=; hostingEnvironmentProfile=; 
                    clientAffinityEnabled=True; clientCertEnabled=False; 
                    clientCertMode=Required; clientCertExclusionPaths=; 
                    hostNamesDisabled=False; domainVerificationIdentifiers=; customDom
                    ainVerificationId=1B27E3BB9DED5150BC07A50F48C1886732C89C02DDC9EC81
                    2E8B4930B40F6825; kind=app; inboundIpAddress=20.119.8.38; 
                    possibleInboundIpAddresses=20.119.8.38; 
                    ftpUsername=TsInfoweb\$TsInfoweb; ftpsHostName=ftps://waws-prod-bl
                    u-399.ftp.azurewebsites.windows.net/site/wwwroot; outboundIpAddres
                    ses=20.246.131.196,20.246.132.249,20.246.133.7,20.237.23.72,20.246
                    .133.29,52.226.203.41,20.119.8.38; possibleOutboundIpAddresses=20.
                    246.131.196,20.246.132.249,20.246.133.7,20.237.23.72,20.246.133.29
                    ,52.226.203.41,20.246.128.222,20.246.133.48,20.246.133.71,20.246.1
                    33.146,20.246.131.255,20.246.133.221,52.226.204.146,20.246.130.23,
                    20.121.144.182,20.121.146.28,20.121.146.62,20.121.150.117,20.121.1
                    47.9,20.121.150.253,20.237.19.240,20.237.19.241,20.237.23.106,20.2
                    37.23.165,20.237.23.217,20.246.129.92,20.246.129.150,20.246.129.20
                    4,20.246.130.37,20.246.130.150,20.119.8.38; containerSize=0; 
                    dailyMemoryTimeQuota=0; suspendedTill=; siteDisabledReason=0; 
                    functionExecutionUnitsCache=; maxNumberOfWorkers=; 
                    homeStamp=waws-prod-blu-399; cloningInfo=; hostingEnvironmentId=; 
                    tags=; resourceGroup=MyNewResGrp; 
                    defaultHostName=tsinfoweb.azurewebsites.net; slotSwapStatus=; 
                    httpsOnly=False; redundancyMode=None; inProgressOperationId=; 
                    geoDistributions=; privateEndpointConnections=; 
                    publicNetworkAccess=; buildVersion=; targetBuildVersion=; 
                    migrationState=; eligibleLogCategories=AppServiceAppLogs,AppServic
                    eAuditLogs,AppServiceConsoleLogs,AppServiceHTTPLogs,AppServiceIPSe
                    cAuditLogs,AppServicePlatformLogs,ScanLogs; 
                    storageAccountRequired=False; virtualNetworkSubnetId=; 
                    keyVaultReferenceIdentity=SystemAssigned; 
                    defaultHostNameScope=Global; privateLinkIdentifiers=}

You can see the same output below

New-AzResource

Well, let’s cross check in Azure Portal if the website TsInfoweb is successfully created. To check that, log in to the Azure Portal and search for App services and then I found that the website has been created successfully, you can check out the below screen shot for your reference.

How to create Azure resource using New-AzResource command

In the same way, you can also create other Azure resources using the New-AzResource Azure PowerShell cmdlet.

If you don’t want the Azure resource anymore, then you can use the Remove-AzResource PowerShell command to remove the Azure resource in seconds.

You may also like following the articles below

Wrapping Up

In this Azure PowerShell article, we discussed the syntax and usage of the New-AzResource Azure PowerShell cmdlet with Examples. Thanks for reading this article !!!