- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从 Azure 自动化 Runbook 在虚拟机上执行 PowerShell,类似于 WinRm 执行/PowerShell 远程处理。
我已经通过 Azure 自动化 GUI 创建了 Azure Runbook,并尝试运行一个能够完美地针对物理机和虚拟机运行的脚本,以获取关键系统信息和端口。我能够在 Azure 中进行身份验证,并且似乎我可以通过 Azure Runbook 执行脚本的某些方面(除非它仅针对 Azure 自动化工作线程运行),例如使用以下命令获取目标 VM 的已安装 PowerShell 版本: $PSVersionTable.PSVersion
所以据我所知,我没有遇到安全/访问问题。
但是,其他几个组件失败如下,我不知道是否需要将模块导入到 Azure 自动化,如果需要,导入哪些模块。或者,如果由于它是针对工作线程而不是虚拟机运行而失败。
以下是我正在运行的一些代码片段:
$computerSystem = Get-CimInstance Win32_ComputerSystem
"CPU: " + $computerCPU.Name
Get-WmiObject -Class Win32_LogicalDisk |
Where-Object {$_.DriveType -ne 5} |
Sort-Object -Property Name |
Select-Object Name, VolumeName, FileSystem, Description, `
@{"Label"="DiskSize(GB)";"Expression"={"{0:N}" -f ($_.Size/1GB) -as [float]}}, `
@{"Label"="FreeSpace(GB)";"Expression"={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}}, `
@{"Label"="%Free";"Expression"={"{0:N}" -f ($_.FreeSpace/$_.Size*100) -as [float]}} |
Format-Table -AutoSize
Get-NetAdapter -Name "*" | Format-Table
Get-NetOffloadGlobalSetting | Format-List
Test-NetConnection -Port 80
以下是错误消息,我强烈怀疑是由于缺少我需要上传的 PowerShell 模块而导致的,但我不确定在哪里可以找到这些错误消息,或者是我没有正确定位虚拟机而是运行此错误消息对抗 AZ 主机? (如果是这样,请提供有关如何定位单个虚拟机的任何好示例):
Get-CimInstance : The specified service does not exist as an installed service.
Get-WmiObject : The specified service does not exist as an installed service.
Get-NetAdapter : The term 'Get-NetAdapter' is not recognized as the name of a cmdlet, function, script file, or operable program.
Get-NetOffloadGlobalSetting : The term 'Get-NetOffloadGlobalSetting' is not recognized as the name of a cmdlet, function, script file, or operable program.
Test-NetConnection : The term 'Test-NetConnection' is not recognized as the name of a cmdlet, function, script file, or operable program.
如果是正确定位虚拟机的问题,我需要一些指导。我怀疑我的目标是运行 Runbook 的工作人员,而不是实际的虚拟机。我正在使用 RunAs 帐户/新的 Azure 自动化安全方法(非经典),因此我不相信证书会发挥作用。以下是我尝试定位虚拟机的方式(我怀疑这是不正确的/应该更改):
$Resources = Get-AzureRmResource -ResourceType "Microsoft.Compute/virtualMachines" -ResourceGroupName "MyTestGroup" -ResourceName "MyTestVM"
ForEach ($Resource in $Resources)
{
# PowerShell Code from Above here
}
更新1:
现在我们已经确定我没有正确定位虚拟机,我尝试了 Joe 的建议,但是当我尝试运行以下命令时,我在 WinRm 上收到错误。我找到了Connect-AzureVM.ps1 ,但我不确定这是否是旧的或与我正在使用的较新的 RunAs 连接一致。这是我当前尝试连接到 VM 并调用 PowerShell 的脚本。
param(
[parameter(Mandatory=$true)][String] 'https://myvmname.eastus.cloudapp.azure.com:5986,
[parameter(Mandatory=$true)][String] 'MyVMName'
)
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
# Get credentials to Azure VM
$Credential = Get-AutomationPSCredential -Name $VMCredentialName
Invoke-Command -ConnectionUri $Uri -Credential $Credential -ScriptBlock {
# My PowerShell Here
}
这是脚本产生的错误。我怀疑它是因为我需要在我的目标虚拟机上导入/创建 WinRM 证书,但不确定 Connect-AzureVM.ps1 是否有效是要使用的正确脚本,或者是否有其他/更多更新的方法可用于 WinRM 访问:
[myvmname.eastus.cloudapp.azure.com] Connecting to remote server myvmname.eastus.cloudapp.azure.com failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (myvmname.eastus.cloudapp.azure.com:String) [], PSRemotingTransportException + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
最佳答案
在虚拟机内以提升的提示符运行此命令
https://gist.github.com/jeffpatton1971/2321f0db8025e48ad8ec13c243153045
从 Runbook 内部执行通常的操作来连接它,但创建一些 session 选项来传递调用命令。
$SessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck
Invoke-Command -ComputerName $VMname -Credential $Credential -UseSSL -SessionOption $SessionOption -ScriptBlock { }
关于powershell - Azure Runbook - 缺少 PowerShell Cmdlet 或未针对 VM 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41984133/
我有一个配置了混合 Runbook Worker 的自动化帐户,突然所有作业每 15 分钟就会重新启动 3 次,并最终因错误而暂停: 工作被暂停。要进行其他故障排除,请检查混合 Runbook 工作组
我有一个运行手册名称“RB_ConnectSQL” workflow RB_ConnectSQL { [OutputType([string])] param (
我对 Azure Runbook 和自动化还很陌生。 我有几个azure Sql 数据库,并且数据库中有我想按顺序运行的存储过程。在使用 On-premises SQL Server 之前,我们有一个
场景: 我有 2 个 Runbook,Runbook A 和 Runbook B。 在 Runbook B 中,我想将 Runbook A 加载到内存中。 以下运行不起作用,有人可以帮我吗? .\ru
背景 我有一个 Azure Runbook(名为 RunStoredProcedure2),定义如下: param( [parameter(Mandatory=$True)] [string] $Sq
我想使用 Runbook 删除另一个 Runbook 输出(Azure 文件共享快照)。 这可能吗?如果您知道什么,请在这里写下 运行手册 1:创建 Azure 文件共享快照 $context = N
背景: 我正在尝试通过 Azure 上的 Runbook 设置脚本。我发现不寻常的是,我可以通过 Azure Powershell Cloud Shell 运行该命令并且它可以工作。但是,当我尝试通过
我有一个每天早上运行的 Azure Runbook。 Runbook 执行“Get-AzureStorageBlob”,但由于我们在存储帐户上启用了防火墙,它现在失败并出现错误: Get-AzureS
所以我有一个运行手册,可以在周末自动关闭和启动我的 Azure VM。然后发送一封事务电子邮件,确认 VPS 已关闭/启动。 我已经如图所示设置了参数。是否有原因说明为什么它在主题行中正确说明了我的虚
我有一个处于运行状态的 PowerShell Azure Runbook。 通过 Azure 门户按“停止”会导致错误消息: "Job could not be stopped". 使用 PowerS
我在自动化帐户中使用 Azure Runbook 已经有一段时间了,但最近我的任务是确定谁在执行该 Runbook。 我注意到当您从作业中获取信息时,有一个名为“执行者”的字段,但似乎该字段已被 MS
我正在尝试设置 Powershell Runbook 来访问 Azure 资源。 我正在按照 this page 上的说明进行操作. 我已为自动化帐户分配了系统身份,但示例脚本根本不起作用。 # Si
我正在尝试设置 Powershell Runbook 来访问 Azure 资源。 我正在按照 this page 上的说明进行操作. 我已为自动化帐户分配了系统身份,但示例脚本根本不起作用。 # Si
我的自动化帐户中有一个 Azure PowerShell 7.1 Runbook,它正在按预期执行。我遇到的唯一问题是运行作业屏幕中的错误输出始终缺少详细信息列。这意味着我必须点击每条记录才能查看其中
我正在尝试运行 API 管理服务的备份。我可以在我的本地计算机上使用下面的代码在我的子所有者登录上下文中在 PS 中执行此操作,不会出现任何问题。 当我尝试将其作为 Runbook 运行时,我只会返回
我有一个 Runbook PowerShell,它会删除所有资源组及其上的所有内容,但带有 RG 的名称。有没有办法做同样的事情,但只能使用与该 RG 关联的标签?运行 Runbook 时,它不会要求
Azure 运行手册。 问题: 如何通过 Runbook 在远程 Azure VM 上运行/调用 powershell 脚本?该脚本放置在远程虚拟机上。 没有 Azure AD,powershell
我创建了一个 Runbook 来处理多维数据集的多个分区。我启动了它,3小时后,它停止了。没有错误消息或警告,输出 Pane 中也没有任何内容。我唯一的消息就是这个 异常 该作业被逐出并随后达到停止状
我无法在 Azure Runbook 中运行“Get-Azurermlog”。我收到错误“术语“Get-Azurermlog”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称”。它是一个标准
我一直在到处寻找,但我什至找不到一个简单的方法来使用 powershell 列出 Runbook...我有 4 个订阅,每个订阅中有几个自动化帐户,当我试图通过控制台浏览来查找特定的 Runbook
我是一名优秀的程序员,十分优秀!