Needing
Needing some help, using powershell, I'm havin trouble creating a datatable and then inserting that datatable into a
1. Create an Active Directory organizational unit (OU) named “finance.”
2. Import the financePersonnel.csv file (found in the “Requirements2” directory) into your Active Directory domain and directly into the finance OU. Be sure to include the following properties:
• First Name
• Last Name
• Display Name (First Name + Last Name, including a space between)
• Postal Code
• Office Phone
• Mobile Phone
3. Create a new database on the Microsoft SQL server instance called “ClientDB.”
4. Create a new table and name it “Client_A_Contacts.” Add this table to your new database.
5. Insert the data from the attached “NewClientData.csv” file (found in the “Requirements2” folder) into the table created in part B4.
New-ADOrganizationalUnit -Name finance -Path "DC=consultingfirm,DC=COM"
Import-Module activedirectory
$ADUsers = Import-csvC:\Users\LabAdmin\Desktop\Requirements2\financePersonnel.csv
$TargetOU = "OU=finance,DC=consultingfirm,DC=com"
foreach ($User in $ADUsers)
{
$Parameters = @{
Name = $User.samAccount
GivenName = $User.First_Name
Surname = $User.Last_Name
PostalCode = $User.PostalCode
DisplayName = $($User.First_Name) + " " + $($User.Last_Name)
OfficePhone = $User.OfficePhone MobilePhone = $User.MobilePhone Path = $TargetOU } New-ADUser @Parameters -PassThru
}
$ConnectionString = "Data Source=.\SQLEXPRESS;initial catalog=master;Integrated Security=True;"
$NewDatabaseName = "ClientDB"
$con = New-Object Data.SqlClient.SqlConnection;
$con.ConnectionString = $ConnectionString;
$con.Open();
$sql = "CREATE DATABASE [$NewDatabaseName] COLLATE SQL_Latin1_General_CP1_CI_AS;"
$cmd = New-Object Data.SqlClient.SqlCommand $sql, $con;
$cmd.ExecuteNonQuery();
Write-Host "Database $NewDatabaseName is created!";
$cmd.Dispose();
$con.Close();
$con.Dispose();
Trending now
This is a popular solution!
Step by step
Solved in 2 steps