用户输入的虚拟机名称应通过powerhsell

时间:2019-11-18 14:21:45

标签: powershell

目的-如果处于停止状态,我正在尝试启动vm            注意-用户将输入Vm name,如果停止,则它将启动,否则将弹出已经处于启动状态的服务器。

$user = 'tooltest'  #Vmname
$rg = Get-AzureRmResourceGroup
$data= $rg.ResourceGroupName
foreach ( $d in $data){
    $res = Get-AzureRmResource | Where-Object {$_.ResourceGroupName -eq $d}
    if ( $res.Name -eq $user){
        Write-Output $res.Name
        Write-Output $res.ResourceGroupName

        $gg = Get-AzureRmVM -ResourceGroupName [string]$res.ResourceGroupName -Name $user -Status

如果我尝试打印$ res.ResourceGroupName-我正在输出资源组名称26次(我在那个RG中有26个资源) 我只想打印RG一次,有人可以帮助我

1 个答案:

答案 0 :(得分:0)

一种过滤输出的方法是仅使用 private Configuration configuration = null; public SqlSession getSqlSession() throws SCExceptions { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(getConfiguration()); return sqlSessionFactory.openSession(); } private Configuration getConfiguration() throws SCExceptions { /** * For debugging purposes, allow a -DdoNotReuseConfiguration. * Setting this flag to any value will cause the server to reload the MyBatis * mapper files with each request. If debugging, this allows a change to be made * and have the server not need to be restarted. */ String doNotReuseConfiguration = System.getProperty("doNotReuseConfiguration"); if(this.configuration == null || doNotReuseConfiguration!=null) { String environmentName = null; if("local-dev-nonjndi".equals(lifeCycle) || "dev".equals(lifeCycle)) { environmentName = "dev"; } else if("local-stage-nonjndi".equals(lifeCycle) || "stage".equals(lifeCycle)) { environmentName = "stage"; } else if("local-prod-nonjndi".equals(lifeCycle) || "prod".equals(lifeCycle)) { environmentName = "prod"; } Environment environment = new Environment(environmentName,transactionFactory,getDataSource()); configuration = new Configuration(environment); configuration.addMappers("com.mycompany.mybatis.mapper"); } return this.configuration; } cmdlet选择想要的对象数。

Select-Object