forked from anwather/My-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFunctions.psm1
More file actions
55 lines (39 loc) · 1.18 KB
/
Copy pathMyFunctions.psm1
File metadata and controls
55 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Function Connect-AzureVM
{
[CmdletBinding()]
Param(
$ResourceGroupName,
$ComputerName
)
$ipAddress = Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName | Where Name -match $ComputerName | Select -ExpandProperty IpAddress
$cmd = "mstsc /v:$ipaddress`:3389"
Invoke-Expression $cmd
}
Function Stop-AzureVMs
{
Param($ResourceGroupName)
#$resourceGroupName = Read-Host "Enter the resource group name"
$vmsAll = Get-AzureRMVM -ResourceGroupName $resourceGroupName
$obj = @()
Class RunningVM
{
[string]$Name
RunningVM([string]$Name)
{
$this.Name = $Name
}
}
foreach ($vm in $vmsAll)
{
$vmRunning = (Get-AzureRMVM -ResourceGroupName $resourceGroupName -Name $vm.OSProfile.ComputerName -Status).Statuses | Where Code -Match "Running"
if ($null -ne $vmRunning)
{
$obj += [RunningVM]::new($vm.OSProfile.ComputerName)
}
}
foreach ($vm in $obj)
{
Stop-AzureRMVM -Name $vm.Name -ResourceGroupName $resourceGroupName -Force -Verbose
}
}
Export-ModuleMember *