如PowerShell脚本中需要传入参数,则必须在脚本中进行声明,如:param([string]arg1,[string]arg2 ),然后通过scriptParameters对象传入。 PowerShell执行成功的结果包含在RunCommandResult对象的Value 1中,如果所输入的PowerShell脚本有语法等操作,则在Value 2中输出详细的异常消息. 在执行PowerShell脚本时,如发现脚本有错误。
以下示例使用az vm run-command命令在 Azure Windows VM 上运行 shell 脚本。 Azure CLI复制 打开Cloud Shell # script.ps1# param(# [string]$arg1,# [string]$arg2# )# Write-Host This is a sample script with parameters $arg1 and $arg2az vm run-command invoke--command-idRunPowerShellScript--...
在使用的时候,需要注意的是参数scriptLines 和 scriptParameters。 下面部分为关键代码,以Java SDK的同步方法runPowerShellScript为例 Azureazure=null;azure=Azure.authenticate(credentials).withSubscription("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");// 获取虚拟机对象VirtualMachinetestvm=azure.virtualMachines().getById...
突然之间,使用PowerShell脚本 Get-AzVirtualNetwork 获取虚拟网络信息时,如果带上 -DefaultProfile $sub 参数,就出现 Azure credentials 错误。 代码: Connect-AzAccount -ServicePrincipal -Credential$pscredential-Tenant$cloudroomTenantId-Environment$region$sub= Set-AzContext -SubscriptionId$cloudroomId-Tenant$cloudro...
突然之间,使用PowerShell脚本 Get-AzVirtualNetwork 获取虚拟网络信息时,如果带上 -DefaultProfile $sub 参数,就出现 Azure credentials 错误。 代码: Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $cloudroomTenantId -Environment $region ...
settings=<<SETTINGS { \"commandToExecute\": \"powershell -command \\\"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.kickstart.rendered)}')) | Out-File -filepath kickstart-ca.ps1\\\" && powershel...
从PowerShell中的AzureRM会话运行此命令,该会话使用Contributor帐户进行身份验证。你可以使用Login-AzureRmAccount命令对Azure进行身份验证。 代码语言:javascript 复制 Invoke-AzureRmVMRunCommand-ResourceGroupName VMResourceGroupName-VMName VMName-CommandId RunPowerShellScript-ScriptPath PathToYourScript ...
按照以下步骤在 Azure Cloud Shell 中编写脚本,以自动创建虚拟机。 备注 通常,使用具有Connect-AzAccount的凭据向 Azure 进行身份验证,但在 Cloud Shell 中,已进行身份验证,因此不需要执行此步骤。 切换到主文件夹: PowerShell复制 Set-Location-Path$HOME ...
1.首先,在 Azure 门户的顶部导航栏中单击“Cloud Shell”按钮 进入CloudShell窗口,我在上篇文章首次使用cloud shell时选择了powershell,因此这次直接进入powershell。如果你想要切换到bash,可以在下图中的红色框中进行选择 2.在cloud shell中运行普通的azure powershell命令 ...
I understand that you're trying to Configure federation between Google Workspace and Azure AD but when running the PowerShell script located in the Configure Azure AD as a Service Provider section, you're running into the above error message when using Azure Cloud Shell. Findings: When working ...