简单的真/假VM搜索??? [英] Simple True/False VM search???

查看:73
本文介绍了简单的真/假VM搜索???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好!我在这里非常新手......我正在寻找一个简单的PS片段,从csv列表中检查我的Azure订阅中是否存在VM(我不关心状态,存储帐户等等)。简单地说"我的列表中的下一个VM是否存在或
不存在 - 返回真或假" - 就是这样!)

Good morning! I'm very much a newbie here... I am looking for a simple PS snippet to check, from a csv list, if a VM exists in my Azure subscription (I don't care about statuses, storage accounts, etc... simply "does the next VM in my list exists or not - return a true or false" - that's it!)

我有我的csv文件并运行了很多脚本执行删除DNS条目和ping /连接测试,从AD删除计算机帐户等等,所以我得到了使用ForEach从csv文件中提取数据的要点...我只需要在Azure中添加快速查找
还要在继续我的其余脚本之前检查是否存在VM ...我将需要从列表中删除任何现有的VM,或者导出所有不存在的,返回的"假QUOT;计算机名称到另一个csv ...

I have my csv files and have run many scripts to do things like remove DNS entries and ping/connection tests, remove computer accounts from AD, etc, so I get the gist of pulling data from csv files using ForEach... I just need to add a quick look-up in Azure to also check for the existence of a VM before continuing on with the rest of my script... I will be needing to have any existing VM's removed from the list as well, or export all non-existing, returned "False" computer names to another csv...

清除泥土?!? 感谢您的任何建议!

Clear as mud?!?  Thanks for any suggestions!

-Scot

推荐答案

我验证了下面的cmdlet将返回当前订阅中的所有虚拟机,然后您可以使用它们进行验证。

I verified the below cmdlet will return all virtual machines currently in the subscription, which you could then use to verify.

Get-AzureRmResource -ResourceGroupName <name> -ResourceType Microsoft.Compute/virtualMachines

另一个选项是下面的cmdlet,它只查找给定的名称,假设你知道你是什么正在寻找。如果找到资源,它会转储资源的详细信息。如果没有找到资源,则不返回任何数据。

Another opition would be the below cmdlet, which only looks for the name given, assuming you know what you're looking for. If it finds the resource, it dumps out details on the resource. If no resource is found, it returns no data.

Get-AzureRmResource -Name <name>

您可以通过在Azure门户中快速启动CloudShell PowerShell实例来自行验证这些。

You can verify these yourself by quickly starting up a CloudShell PowerShell instance in the Azure Portal.

来源:  https://docs.microsoft.com/powershell/module/azurerm .resources / get-azurermresource?view = azurermps-6.13.0

Source: https://docs.microsoft.com/powershell/module/azurerm.resources/get-azurermresource?view=azurermps-6.13.0


这篇关于简单的真/假VM搜索???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆