Skip to content

Commit 2b18245

Browse files
committed
added configuration params in importing departments
1 parent 1314e29 commit 2b18245

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

departments.ps1

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function GetDataFromSqlDatabase($Query, $ConnectionString) {
1+
function PerfromQuery($Query, $ConnectionString) {
22
try {
33
# Initialize connection and query information
44
# Connect to the SQL server
@@ -8,43 +8,39 @@ function GetDataFromSqlDatabase($Query, $ConnectionString) {
88
$SqlCmd.Connection = $SqlConnection;
99
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
1010

11+
#Query to get all person information adjust to liking#
1112
$SqlCmd.CommandText = $query;
1213
$SqlAdapter.SelectCommand = $SqlCmd;
1314

1415
$DataSet = New-Object System.Data.DataSet;
1516
$SqlAdapter.Fill($DataSet) | out-null;
16-
return $DataSet.Tables[0] | Select-Object -Property * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors;
17+
$sqlData = $DataSet.Tables[0];
18+
return $sqlData | Select-Object -Property * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors;
1719
}
1820
catch {
1921
Write-Error "Something went wrong while connecting to the SQL server";
2022
Write-Error $_.Exception.Message;
2123
Exit;
2224
}
23-
finally
24-
{
25-
if($SqlConnection -and $SqlConnection.State -eq [System.Data.ConnectionState]::Open)
26-
{
27-
$SqlConnection.Close()
28-
}
29-
}
3025
}
3126

32-
$server = ""
33-
$database = ""
34-
$userId = ""
35-
$password = ""
27+
$config = ConvertFrom-Json $configuration
28+
$server = $config.server
29+
$database = $config.database
30+
$userId = $config.user
31+
$password = $config.password
3632
$connectionString = "Data Source=$server;Initial Catalog=$database;User Id=$userId;Password=$password;";
37-
$languageId = 2;
33+
$languageId = "(1,2)"; # 1=NL, 2=EN
3834

3935
#Query to get all department information adjust to liking#
4036
$departmentsQuery = "SELECT [Organisatorische_eenheid] as [ExternalId]
4137
,[Omschrijving] as [DisplayName]
4238
,[Omschrijving] as [Name]
4339
,[Leidinggevende] as [ManagerId]
4440
,[Parent] as [ParentDepartmentId]
45-
FROM [dbo].[T4E_IAM_OrganizationalUnits] WHERE [lang_id] = $languageId"
41+
FROM [dbo].[T4E_IAM_OrganizationalUnits] WHERE [lang_id] in $languageId"
4642

47-
$departments = GetDataFromSqlDatabase -Query $departmentsQuery -ConnectionString $connectionString
43+
$departments = PerfromQuery -Query $departmentsQuery -ConnectionString $connectionString
4844

4945
Foreach ($department in $departments) {
5046
Write-Output $department | ConvertTo-Json -Depth 10;

0 commit comments

Comments
 (0)