Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建Powershell脚本以创建Azure API管理资源_Azure_Powershell_Azure Api Management_Api Management_Apim - Fatal编程技术网

如何创建Powershell脚本以创建Azure API管理资源

如何创建Powershell脚本以创建Azure API管理资源,azure,powershell,azure-api-management,api-management,apim,Azure,Powershell,Azure Api Management,Api Management,Apim,我试图弄清楚如何从脚本创建API管理资源和API管理API。我相信有两个选择: 使用AzureRm.ApiManagement中的powershell管理api 为此,我相信要使用的两个命令是: 新AzureRmApiManagement 新AzureRmApiManagementApi 使用管理RESTAPI 为此,我认为要创建资源,您需要使用第一个选项,然后可以通过Invoke RestMethod powershell命令使用以下方法: PUT{subscriptionId}/reso

我试图弄清楚如何从脚本创建API管理资源和API管理API。我相信有两个选择:

  • 使用AzureRm.ApiManagement中的powershell管理api

    为此,我相信要使用的两个命令是:

    新AzureRmApiManagement

    新AzureRmApiManagementApi

  • 使用管理RESTAPI

    为此,我认为要创建资源,您需要使用第一个选项,然后可以通过Invoke RestMethod powershell命令使用以下方法:

    PUT{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api/{apid}?api版本=2019-01-01

  • 我只想传递新管理api资源的名称和devlab的名称,以便在下面创建它,并创建它,然后在下面创建一个与产品(或与无限默认产品关联的api…以较容易的为准)无关的api

    有人可以帮助使用powershell脚本来执行此操作吗

    谢谢。

    当您运行命令“New AzureRmApiManagementApi”时,您只需创建一个api,该api将不会添加到产品中。您需要运行“addazurermapimanagementapitoproduct”命令将api添加到产品中。我的脚本如下

    $ResourceGroupName=""
    $sku=""
    $name="" 
    $Location=""                   
    $Organization=""
    $AdminEmail=""
    $apiName=" #the name of the web API."
    $url="" #the URL of the web service that exposes the API.
    $path="" #the web API path, which is the last part of the API's public URL and corresponds to the Web API URL suffix field in the admin portal.
    
    #login azure
    Connect-AzureRmAccount
    
    #create api management instance with required parameters
    New-AzureRmApiManagement -ResourceGroupName $ResourceGroupName -Name $name -Sku $sku -Location $Location -Organization $Organization -AdminEmail $AdminEmail
    
    $ApiMgmtContext =New-AzureRmApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $name
    
    #create api
    $api = New-AzureRmApiManagementApi -Context $ApiMgmtContext -Name $apiName -ServiceUrl $url -Protocols @("http", "https") -Path $path
    
    #run the command if you do not know product id
    Get-AzureRmApiManagementProduct -Context $ApiMgmtContext
    
    #add api to product
    Add-AzApiManagementApiToProduct -Context $ApiMgmtContext -ProductId "" -ApiId $api.ApiId
    

    有关Azure API管理powershell命令的更多详细信息,请参阅

    @JackSojourn这对您合适吗?你有什么更新吗?谢谢吉姆!正是我需要的。