Skip to content

Commit 2d62e42

Browse files
authored
Merge pull request #209 from bharath-bheemarasetti/master
Script for assiging SLAs based on Hyper-V VM tags
2 parents b7e3c98 + a207264 commit 2d62e42

File tree

10 files changed

+554
-0
lines changed

10 files changed

+554
-0
lines changed

HyperV/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Below are the detailed steps to run the PowerShell script to assign SLA Domains to Hyper-V virtual machines based on the tags assigned to them in SCVMM. The command can run the script once it passes the required parameters:
2+
3+
`.\Set-SLA-Using-VMTag.ps1 -path <absolute path to file containing the cluster detatils> -password_file_path <absolute path to the file containing the encrypted vault password> -mapping_file_path <absolute path to file containing the SLA to tag mapping> -verbose <true or false to enable extra logs> -dry_run <true or false to enable dry run>`
4+
5+
**Important:** USE AT YOUR OWN RISK. Rubrik does not officially support the community tools. Carefully investigate a community tool before using it. Always test a community tool on non-production data before using the tool with production data.
6+
7+
Prerequisites:
8+
---------------
9+
10+
The script needs the following prerequisites to run:
11+
12+
1. Install PowerShell 7 on the machine where SCVMM is hosted. We recommend using the latest version of PowerShell 7 which can be installed using this [installer](https://github.com/PowerShell/PowerShell/releases/download/v7.3.0/PowerShell-7.3.0-win-x64.msi).
13+
14+
2. The Rubrik, SecretStore, and SecretManagement PowerShell modules need to be installed using the command in PowerShell 6.0+ window with the command **Install-Module -Name <module\_name>**.
15+
16+
3. Create a service account with admin access. Details steps are mentioned below.
17+
18+
19+
Instructions
20+
------------------------
21+
22+
The script requires the following parameters:
23+
24+
1. The path to the CSV file containing the cluster details, user_id and secret of the service account.
25+
26+
1. Follow the steps mentioned [here](service_account.md) to create the service account.
27+
28+
2. Follow the steps mentioned [here](windows_vault.md) to store them in the Windows secret store.
29+
30+
3. Save the file in CSV format with a separate row for every cluster in the format "cluster IP address", "Name of the secret for user", "Name of the secret for secret". Sample content of the file:
31+
32+
1. ```
33+
10.0.35.104,rubrik_user,rubrik_key
34+
10.0.34.151,new_user,new_key
35+
```
36+
37+
2. The parameter password\_file\_path takes a text file that contains the encrypted password to the vault used to store the service account user_id and secret. This can be created using the below command
38+
"vault\_password" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "path\_to\_store\_the\_password"
39+
40+
3. The path to the JSON file containing the mapping between the tag specified in SCVMM and the SLA Domain that needs to be assigned. Sample content of the file:
41+
42+
1. {
43+
"Test-Gold": "Gold",
44+
"Test-Silver": "Silver",
45+
"Test-Bronze": "Bronze",
46+
"Tag-Bharath": "Bharath",
47+
"Tag-Fail": "Tag"
48+
}
49+
50+
51+
52+
4. The parameter -verbose indicates whether to have extra logs enabled or not. Passing this as true will print the entire list of virtual machines in SCVMM, Rubrik, and hosts in SCVMM with complete details.
53+
54+
5. The parameter -dry\_run indicates whether to assign the SLA Domain or just display the changes that are going to be done.
55+
56+
57+
Debugging:
58+
----------
59+
60+
A log file is created at “%localappdata%/<timestamp>.log for each run of the script. When the script encounters errors, a log is added to the Windows events with the event id as `3001`, source name as `Set-SLA-Using-VMTag.ps1,` and category as 1 for terminal events and as 2 for info events.
61+
Example:
62+
63+
![](attachments/2661974167/2661549149.png)
64+
65+
A task can be scheduled in the task scheduler to perform an action such as sending a mail whenever this event is published.
66+
67+
Limitations/Notes:
68+
------------------
69+
70+
1. The script cannot differentiate virtual machines that are present in the same host with the same name. Hence, the script will log an appropriate error both in the log file and in the Windows event logs. This behavior is fixed in CDM versions 9.0+ and will not require any changes in the current script once CDM is upgraded to that version.
71+
72+
2. The script will overwrite the SLA Domain for the virtual machines even if it is already protected in case the tag/mapping is changed.
73+
74+
75+
Steps to run the script from the task scheduler:
76+
------------------------------------------------
77+
78+
The script can be configured to run periodically from the task scheduler on the machine where SCVMM is hosted.
79+
80+
1. In the actions section, specify the action as “Start a program”.
81+
82+
2. Specify the path of the PowerShell 7 executable in the Program/script section.
83+
Example: `"C:\Program Files\PowerShell\7\pwsh.exe"`
84+
85+
3. In the arguments section, pass the path of the script followed by the arguments to the script.
86+
Example:
87+
88+
```java
89+
C:\Users\administrator.RUBRIK-LAB\Desktop\Set-SLA-Using-VMTag.ps1 -path C:\Users\administrator.RUBRIK-LAB\Desktop\creds.csv -password_file_path C:\Users\administrator.RUBRIK-LAB\Desktop\Password.txt -mapping_file_path C:\Users\administrator.RUBRIK-LAB\Desktop\mapping.json -verbose True
90+
```
91+
92+
93+
![](attachments/2661974167/2662498358.png)
94+
95+
A sample exported task from the task scheduler is attached below.
96+
97+
[![](attachments/thumbnails/2661974167/2699788369)](attachments/2661974167/2699788369.xml)

0 commit comments

Comments
 (0)