-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ps1
71 lines (53 loc) · 2.86 KB
/
run.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
.SYNOPSIS
Starts or stops all VMs found in a given session based on the tags provided.
.DESCRIPTION
Starts or stops all VMs found in a given session based on the tags provided.
Logs in to a Azure subcription given the a user assigned managed identity or based on users input.
Checks for each VM if they are not Running, have a tag `ManuallyStopped`, or `PowerOffDisabled`.
For each VM check the `PowerOnTime` and `PowerOffTime` and convert the values into a date.
Compares the current date with the Power Times based on the time windows start or stop the VM
.EXAMPLE
./run.ps1
Runs Start-Vm.ps1
.EXAMPLE
./run.ps1 -stop
Runs Stop-Vm.ps1
.NOTES
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
**THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED AS IS**
**WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED**
**TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.**
We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and
to reproduce and distribute the object code form of the Sample Code,
provided that You agree:
1. To not use Our name, logo, or trademarks to market Your software
product in which the Sample Code is embedded;
2. Include a valid copyright notice on Your software product in which
the Sample Code is embedded; and
3. To indemnify, hold harmless, and defend Us and Our suppliers from and
against any claims or lawsuits, including attorneys' fees, that arise
or result from the use or distribution of the Sample Code.
Please note: None of the conditions outlined in the disclaimer above will supersede terms and conditions contained within the Premier Customer Services Description.
**ALL CODE MUST BE TESTED BY ANY RECIPIENTS AND SHOULD NOT BE RUN IN A PRODUCTION ENVIRONMENT WITHOUT MODIFICATION BY THE RECIPIENT.**
Author: Mark Warneke [[email protected]](mailto:[email protected])
Created: 18-12-2020
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose.
This respository assumes that you are familiar with the programming language that is being demonstrated and the tools that are used to create and debug procedures.
#>
[CmdletBinding()]
param (
[switch] $Stop,
[switch] $SkipLogin
)
# Make functions available by dot sourcing scripts.
Import-Module (Join-Path $PSScriptRoot 'src' 'Az.Compute.LifeCycle') -Force
if (-Not $SkipLogin) {
Connect-AzAccount -Identity
}
if ($stop) {
Stop-Vm -Verbose
}
else {
Start-Vm -Verbose
}