Skip to content

Commit 9d9067a

Browse files
Statistics Action Pack
1 parent e82e118 commit 9d9067a

24 files changed

+3430
-0
lines changed

Statistics/BestPractice.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Specify the SQL Server name and the database name directly in the script _LIB_\StatisticLib.ps1.
2+
Use the integrated login
3+
4+
5+
Integrated Authentication
6+
-------------------------
7+
Create a local target in ScriptRunner with the option 'Impersonated Thread Mode'.
8+
Assign a credential to this target that has sufficient permissions for the SQL database.
9+
10+
11+
Integrated Authentication with Jump Host
12+
----------------------------------------
13+
Create target as described for integrated authentication.
14+
For special targets, e.g. O365 targets, specify this target as a jump host
15+
16+
17+
Warning: Do not save the SQL Server user account data in the _LIB_\StatisticLib.ps1 script!
18+
19+
----------------------------------------------------------------------------------------------------------------
20+
21+
Falls möglich den SQL Server Namen und den Datenbanknamen direkt im Script _LIB_\StatisticLib.ps1 festlegen.
22+
Nutzen der integrierten Anmeldung, die Anmeldung mit einer SQL Server Authentifizierung aus Sicherheitsgründen nur mit einem Credential nutzen.
23+
24+
Integrierte Anmeldung
25+
---------------------
26+
Im ScriptRunner ein lokales Zielsystem mit der Option 'Thread-Impersonierungs-Modus' anlegen.
27+
Diesem Zielsystem ein Benutzerkonto zuordnen, das ausreichend für die Datenbank berechtigt ist.
28+
29+
Integrierte Anmeldung mit Jump Host
30+
-----------------------------------
31+
Zielsystem anlegen, wie bei integrierter Anmeldung beschrieben.
32+
Bei speziellen Zielsystemen, z.B. O365 Zielsystemen, dieses Zielsystem als Jump Host angeben
33+
34+
Warnung: Hinterlegen Sie nicht die Daten des SQL Server Benutzerkontos, fest im Script _LIB_\StatisticLib.ps1!

Statistics/DB/Add-StaDBSqlServer.ps1

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

Statistics/DB/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Database
2+
3+
+ [Add-StaDBSqlServer.ps1](./Add-StaDBSqlServer.ps1)
4+
5+
Creates the database, tables, storded procedures in the MS Sql Server

Statistics/Samples/New-AADUser.ps1

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#Requires -Version 4.0
2+
#Requires -Modules AzureAD
3+
4+
<#
5+
.SYNOPSIS
6+
Connect to Azure Active Directory and creates a user
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Azure Active Directory Powershell Module v2
20+
Requires the library script StatisticLib.ps1
21+
22+
.LINK
23+
https://github.com/scriptrunner/ActionPacks/tree/master/Statistics/Samples
24+
25+
.Parameter UserPrincipalName
26+
[sr-en] Specifies the user ID for this user
27+
[sr-de] UPN des neuen Benutzers
28+
29+
.Parameter Password
30+
[sr-en] Specifies the new password for the user
31+
[sr-de] Initiales Passwort
32+
33+
.Parameter DisplayName
34+
[sr-en] Specifies the display name of the user
35+
[sr-de] Anzeigename
36+
37+
.Parameter Enabled
38+
[sr-en] Specifies whether the user is able to log on using their user ID
39+
[sr-de] Aktiviere Log On
40+
41+
.Parameter FirstName
42+
[sr-en] Specifies the first name of the user
43+
[sr-de] Vorname
44+
45+
.Parameter LastName
46+
[sr-en] Specifies the last name of the user
47+
[sr-de] Nachname
48+
49+
.Parameter PostalCode
50+
[sr-en] Specifies the postal code of the user
51+
[sr-de] Postleitzahl
52+
53+
.Parameter City
54+
[sr-en] Specifies the city of the user
55+
[sr-de] Ort
56+
57+
.Parameter Street
58+
[sr-en] Specifies the street address of the user
59+
[sr-de] Strasse
60+
61+
.Parameter PhoneNumber
62+
[sr-en] Specifies the phone number of the user
63+
[sr-de] Telefonnummer
64+
65+
.Parameter MobilePhone
66+
[sr-en] Specifies the mobile phone number of the user
67+
[sr-de] Telefonnummer mobil
68+
69+
.Parameter Department
70+
[sr-en] Specifies the department of the user
71+
[sr-de] Abteilung
72+
73+
.Parameter ForceChangePasswordNextLogin
74+
[sr-en] Forces a user to change their password during their next logon
75+
[sr-de] Benutzer muss das Passwort beim nächsten LogIn ändern
76+
77+
.Parameter ShowInAddressList
78+
[sr-en] Specifies show this user in the address list
79+
[sr-de] Benutzer in der Adresslisten anzeigen
80+
81+
.Parameter UserType
82+
[sr-en] Type of the user
83+
[sr-de] Benutzertyp
84+
85+
.Parameter CostReduction
86+
[sr-en] Cost saving through execution per ScriptRunner, in seconds
87+
[sr-de] Zeitersparnis, in Sekunden
88+
#>
89+
90+
param(
91+
[Parameter(Mandatory = $true)]
92+
[string]$UserPrincipalName,
93+
[Parameter(Mandatory = $true)]
94+
[string]$Password,
95+
[Parameter(Mandatory = $true)]
96+
[string]$DisplayName,
97+
[Parameter(Mandatory = $true)]
98+
[bool]$Enabled,
99+
[string]$FirstName,
100+
[string]$LastName,
101+
[string]$PostalCode,
102+
[string]$City,
103+
[string]$Street,
104+
[string]$PhoneNumber,
105+
[string]$MobilePhone,
106+
[string]$Department,
107+
[bool]$ForceChangePasswordNextLogin,
108+
[bool]$ShowInAddressList,
109+
[int]$CostReduction = 600,
110+
[ValidateSet('Member','Guest')]
111+
[string]$UserType = 'Member'
112+
)
113+
114+
try{
115+
$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
116+
$PasswordProfile.Password = $Password
117+
$PasswordProfile.ForceChangePasswordNextLogin = $ForceChangePasswordNextLogin
118+
$nick = $UserPrincipalName.Substring(0, $UserPrincipalName.IndexOf('@'))
119+
$Script:User = New-AzureADUser -UserPrincipalName $UserPrincipalName -DisplayName $DisplayName -AccountEnabled $Enabled -MailNickName $nick -UserType $UserType `
120+
-PasswordProfile $PasswordProfile -ShowInAddressList $ShowInAddressList | Select-Object *
121+
if($null -ne $Script:User){
122+
if($PSBoundParameters.ContainsKey('FirstName') -eq $true ){
123+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -GivenName $FirstName
124+
}
125+
if($PSBoundParameters.ContainsKey('LastName') -eq $true ){
126+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -Surname $LastName
127+
}
128+
if($PSBoundParameters.ContainsKey('PostalCode') -eq $true ){
129+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -PostalCode $PostalCode
130+
}
131+
if($PSBoundParameters.ContainsKey('City') -eq $true ){
132+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -City $City
133+
}
134+
if($PSBoundParameters.ContainsKey('Street') -eq $true ){
135+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -StreetAddress $Street
136+
}
137+
if($PSBoundParameters.ContainsKey('PhoneNumber') -eq $true ){
138+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -TelephoneNumber $PhoneNumber
139+
}
140+
if($PSBoundParameters.ContainsKey('MobilePhone') -eq $true ){
141+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -Mobile $MobilePhone
142+
}
143+
if($PSBoundParameters.ContainsKey('Department') -eq $true ){
144+
$null = Set-AzureADUser -ObjectId $Script:User.ObjectId -Department $Department
145+
}
146+
$Script:User = Get-AzureADUser | Where-Object {$_.UserPrincipalName -eq $UserPrincipalName} | Select-Object *
147+
148+
LogExecution -CostSavingsSeconds $CostReduction
149+
if($SRXEnv) {
150+
$SRXEnv.ResultMessage = $Script:User
151+
}
152+
else{
153+
Write-Output $Script:User
154+
}
155+
}
156+
else{
157+
if($SRXEnv) {
158+
$SRXEnv.ResultMessage = "User not created"
159+
}
160+
Throw "User not created"
161+
}
162+
}
163+
finally{
164+
165+
}

Statistics/Samples/New-AzVM.ps1

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules Az.Compute
3+
4+
<#
5+
.SYNOPSIS
6+
Creates a Azure virtual machine
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module Az
20+
Requires Library script AzureAzLibrary.ps1
21+
Requires the library script StatisticLib.ps1
22+
23+
.LINK
24+
https://github.com/scriptrunner/ActionPacks/blob/master/Statistics/Samples
25+
26+
.Parameter Name
27+
[sr-en] Specifies a name for the virtual machine
28+
[sr-de] Name der virtuellen Maschine
29+
30+
.Parameter ResourceGroupName
31+
[sr-en] Specifies the name of a resource group
32+
[sr-de] Name der resource group die die virtuelle Maschine enthält
33+
34+
.Parameter Location
35+
[sr-en] Specifies the location for the virtual machine
36+
[sr-de] Ort der virtuellen Maschine
37+
38+
.Parameter AdminCredential
39+
[sr-en] The administrator credentials for the VM
40+
[sr-de] Administratoranmeldeinformationen für die VM
41+
42+
.Parameter DataDiskSizeInGb
43+
[sr-en] Specifies the sizes of data disks in GB
44+
[sr-de] Größe von Datenträgern in GB
45+
46+
.Parameter EnableUltraSSD
47+
[sr-en] Use UltraSSD disks for the vm
48+
[sr-de] UltraSSD-Datenträger verwenden für die virtuelle Maschine
49+
50+
.Parameter Image
51+
[sr-en] The friendly image name upon which the VM will be built
52+
[sr-de] Imagename, auf dem die VM erstellt wird
53+
54+
.Parameter AllocationMethod
55+
[sr-en] The IP allocation method for the public IP which will be created for the VM
56+
[sr-de] IP-Zuweisungsmethode für die öffentliche IP-Adresse
57+
58+
.Parameter SecurityGroupName
59+
[sr-en] The name of a new (or existing) network security group (NSG) for the created VM to use.
60+
If not specified, a name will be generated
61+
[sr-de] Name einer neuen (oder vorhandenen) Netzwerksicherheitsgruppe (NSG) für die erstellte VM.
62+
Wenn nicht angegeben, wird ein Name generiert
63+
64+
.Parameter SubnetName
65+
[sr-en] The name of a new (or existing) subnet for the created VM to use.
66+
If not specified, a name will be generated
67+
[sr-de] Name eines neuen (oder vorhandenen) Subnetzes
68+
Wenn nicht angegeben, wird ein Name generiert
69+
70+
.Parameter VirtualNetworkName
71+
[sr-en] The name of a new (or existing) virtual network for the created VM to use.
72+
If not specified, a name will be generated
73+
[sr-de] Name eines neuen (oder vorhandenen) virtuellen Netzwerks
74+
Wenn nicht angegeben, wird ein Name generiert
75+
76+
.Parameter CostReduction
77+
[sr-en] Cost saving through execution per ScriptRunner, in seconds
78+
[sr-de] Zeitersparnis, in Sekunden
79+
#>
80+
81+
param(
82+
[Parameter(Mandatory = $true)]
83+
[string]$Name,
84+
[Parameter(Mandatory = $true)]
85+
[pscredential]$AdminCredential,
86+
[string]$ResourceGroupName,
87+
[int]$DataDiskSizeInGb,
88+
[switch]$EnableUltraSSD,
89+
[ValidateSet('Win2016Datacenter', 'Win2012R2Datacenter', 'Win2012Datacenter', 'Win2008R2SP1', 'UbuntuLTS', 'CentOS', 'CoreOS', 'Debian', 'openSUSE-Leap', 'RHEL', 'SLES')]
90+
[string]$Image = "Win2016Datacenter",
91+
[ValidateSet('Static', 'Dynamic')]
92+
[string]$AllocationMethod,
93+
[string]$Location,
94+
[string]$SecurityGroupName,
95+
[string]$SubnetName,
96+
[string]$VirtualNetworkName,
97+
[int]$CostReduction = 1200
98+
)
99+
100+
Import-Module Az
101+
102+
try{
103+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
104+
'Confirm' = $false
105+
'Credential' = $AdminCredential
106+
'Name' = $Name
107+
'Image' = $Image
108+
'EnableUltraSSD' = $EnableUltraSSD}
109+
110+
if([System.String]::IsNullOrWhiteSpace($ResourceGroupName) -eq $false){
111+
$cmdArgs.Add('ResourceGroupName',$ResourceGroupName)
112+
}
113+
if([System.String]::IsNullOrWhiteSpace($Location) -eq $false){
114+
$cmdArgs.Add('Location',$Location)
115+
}
116+
if([System.String]::IsNullOrWhiteSpace($SecurityGroupName) -eq $false){
117+
$cmdArgs.Add('SecurityGroupName',$SecurityGroupName)
118+
}
119+
if([System.String]::IsNullOrWhiteSpace($SubnetName) -eq $false){
120+
$cmdArgs.Add('SubnetName',$SubnetName)
121+
}
122+
if([System.String]::IsNullOrWhiteSpace($VirtualNetworkName) -eq $false){
123+
$cmdArgs.Add('VirtualNetworkName',$VirtualNetworkName)
124+
}
125+
if([System.String]::IsNullOrWhiteSpace($AllocationMethod) -eq $false){
126+
$cmdArgs.Add('AllocationMethod',$AllocationMethod)
127+
}
128+
if($DataDiskSizeInGb -gt 0){
129+
$cmdArgs.Add('DataDiskSizeInGb',$DataDiskSizeInGb)
130+
}
131+
132+
$ret = New-AzVM @cmdArgs
133+
LogExecution -CostSavingsSeconds $CostReduction
134+
135+
if($SRXEnv) {
136+
$SRXEnv.ResultMessage = $ret
137+
}
138+
else{
139+
Write-Output $ret
140+
}
141+
}
142+
catch{
143+
throw
144+
}
145+
finally{
146+
}

0 commit comments

Comments
 (0)