Question

A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create...

A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create a comment and include your first and last name along with your student ID.

Note: The remainder of this task shall be completed within the same script file, “restore.ps1.”

B. Write a single script within the “restore.ps1” file that performs all of the following functions without user interaction:

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 UCERTIFY3 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.

C. Apply exception handling using try-catch for System.OutOfMemoryException.

D. Run the script within the uCertify environment. After the script executes successfully, run the following cmdlets individually from within your Requirements2 directory:
1. Get-ADUser -Filter * -SearchBase “ou=finance,dc=ucertify,dc=com” -Properties DisplayName,PostalCode,OfficePhone,MobilePhone > .\AdResults.txt
2. Invoke-Sqlcmd -Database ClientDB –ServerInstance .\UCERTIFY3 -Query ‘SELECT * FROM dbo.Client_A_Contacts’ > .\SqlResults.txt

Note: Ensure you have all of the following files intact within the “Requirements2” folder, including the original files:

“restore.ps1”

“AdResults.txt”

“SqlResults.txt”

E. Compress the “Requirements2” folder as a ZIP archive. When you are ready to submit your final task, run the Get-FileHash cmdlet against the “Requirements2” ZIP archive. Note the hash value and place it into the comment section when you submit your task.

Homework Answers

Answer #1

:: Solution ::

1. Get-ADUser -Filter * -SearchBase “ou=finance,dc=ucertify,dc=com” -Properties DisplayName,PostalCode,OfficePhone,MobilePhone > .\AdResults.txt
2. Invoke-Sqlcmd -Database ClientDB –ServerInstance .\UCERTIFY3 -Query ‘SELECT * FROM dbo.Client_A_Contacts’ > .\SqlResults.txt

Note: Ensure you have all of the following files intact within the “Requirements2” folder, including the original files:

• “restore.ps1”

• “AdResults.txt”

• “SqlResults.txt”

E. Compress the “Requirements2” folder as a ZIP archive. When you are ready to submit your final task, run the Get-FileHash cmdlet against the “Requirements2” ZIP archive. Note the hash value and place it into the comment section when you submit your task.

The submission should also include the SQL results and AD results files.

The submission contains the PowerShell script and two input csv files. The hard coded paths to the input files will need to be removed the script should use the local files to run. The submission should also include the SQL results and AD results files.
Please inform if any extra information is needed.

Param
(
[string]$OUName = "finance",
[string]$ADUsersCSVPath = "c:\Users\Administrator\Documents\gitRepos\powershell\Requirements2\financePersonnel.csv",
[string]$SQLDataCSVPath = "c:\Users\Administrator\Documents\gitRepos\powershell\Requirements2\NewClientData.csv",
[string]$OUPath = "DC=nealpimentel,DC=com",
[string]$Database = "ClientDB",
[string]$SqlServer = "DCSVR01"
)
Function Add-ADOU
{
Param
(
[Parameter(Mandatory = $true)]
[string]$OUName,
[Parameter(Mandatory = $false)]
[string]$OUPath = "DC=seandersontech,DC=com"
)
Write-Host -ForegroundColor DarkCyan "Configuring AD"
Write-Host -ForegroundColor Green "Creating OU" $OUName

New-ADOrganizationalUnit -Name $OUName -Path $OUPath

Write-Host -ForegroundColor Magenta "Done"
}
Function Import-ADUsers
{
Param
(
[Parameter(Mandatory)]
[string]$BackupCsvPath,
[Parameter(Mandatory)]
[string]$OUPath
)

Write-Host -ForegroundColor Blue "Importing Users"

$BackUPADUsersBase = Import-CSV $BackUPCSVPath

$ADUsers = $BackUPADUsersBase | Select-Object
@{Name = 'BobAccountNAme' ; Expression = {$_.first_name + $_.last_name}}
@{Name = 'Name' ; Expression = {$_.first_name + " " + $_.last_name}},
@{Name = 'DisplayName' ; Expression = {$_.first_name + " " + $_.last_name}},
@{Name = 'GivenName' ; Expression = {$_.first_name}},
@{Name = 'Surname' ; Expression = {$_.last_name}},
@{Name = 'PostalCode' ; Expression = {$_.zip}},
@{Name = 'OfficePhone' ; Expression = {$_.phone1}},
@{Name = 'MobilePhone' ; Expression = {$_.phone2}}

$ADUsers | New-ADUser -Path $OUPath

Write-Host -ForegroundColor Magenta "Done"
}
Function Add-SQLDB
{
Param
([Parameter(Mandatory)]
[string]$Database,
[Parameter(Mandatory)]
[string]$SqlServer,
[string]$Table = "Client_A_Contacts",
[string]$SqlServerPath = "SQLSERVER:\SQL\DCSVR01\"
)

Write-Host -ForegroundColor DarkRed "Configuring SQL"
Write-Host -ForegroundColor Gray "Creating Database" $Database
  
$svr = Get-Item ($SqlServerPath + "Default")
$db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database -ArgumentList $svr, $Database
$db.Create()

Write-Host -ForegroundColor Blue $db.Name "Created" $db.CreateDate

Write-Host -ForegroundColor DarkGreen "Creating Table " $Table

$CreateTable =
Use ClientDB
CREATE TABLE Client_A_Contacts
(
first_name varchar(100) NOT NULL,
last_name varchar(100) NOT NULL,
samAccount varchar(100) NOT NULL,
city varchar(100) NOT NULL,
county varchar(100) NOT NULL,
zip int NOT NULL,
phone1 varchar(20) NOT NULL,
phone2 varchar(20) NOT NULL
)
  

Invoke_SqlCmd -ServerInstance $SqlServer -Database $Database -Query $CreateTable

Write-Host -ForegroundColor Magenta "Done"
}
Function Import-SQLData
{
Param
(
[Parameter(Mandatory)]
[string]$CSVPath,
[Parameter(Mandatory)]
[string]$Database,
[Parameter(Mandatory)]
[string]$SqlServer
)

Write-Host -ForegroundColor DarkGreen "Importing SQL Data"

$SQLData = Import-Csv $CSVPath

$TableDate = INSERT INTO dbo.Client_A_Contacts
VALUES

$n = 0

ForEach ( $user in $SQLData )
{
$n = 1
$TableData += "('" + $user.first_name
$TableData += "', '" + $user.last_name
$TableData += "', '" + $user.samAccount
$TableData += "', '" + $user.city
$TableData += "', '" + $user.county
$TableData += "', " + $user.zip
$TableData += ", '" + $user.phone1
$TableData += "', '" + $user.phone2
$TableData += "')"
}

Invoke-Sqlcmd -ServerInstance $SqlServer -Database $Database -Query $TableData

Write-Host -ForegroundColor Red "Done"
}
Add-ADOU -OUName

$OUPath = "OU=" + $OUName + "," + $OUPath

Import-ADUsers -BackupCsvPath $ADUsersCSVPath -OUPath $OUPath

Add-SQLDB -Database $Database -SqlServer $SqlServer

Import-SQLData -CSVPath $SQLDataCSVPath -Database $Database -SqlServer $SqlServer

Please rate my answer thank you...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Using functions,...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Using functions, create a loop to get data from user Name Address City State Zip Phone Store that data in a text file, appending to the end of the file Loop should have an option to quit before entering next set of data The file should Be in CSV format Have a header line
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
Time: 10 minutes Objective: Create, view and extract tar archives. Description:  In this activity, the student will...
Time: 10 minutes Objective: Create, view and extract tar archives. Description:  In this activity, the student will use the tar utility to create, view, and extract a tar archive and use it options to name the tar file and view files as they are being archived and extracted. 1.     Start your Linux server virtual machine and sign-on with your individual user ID.  All Activities should begin in your home directory. 2.    Create a directory by typing  mkdir Act6-1 and press Enter.  Switch to this new directory...
Create shell scripts, each in its own .sh file. Please include a shebang line at the...
Create shell scripts, each in its own .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that uses sed to replace all instances of the name "Lizzy" with "Elizabeth" in a text file. Save the updated text in a new file named after the original text file with "-formal" appended before the file extension, e.g. old.txt -> old-formal.txt. Test this script on the data-shell/writing/data text files....
Hello What I need is a script to delete all files from the month and leave...
Hello What I need is a script to delete all files from the month and leave only one ( the final one ) It will be marked as _final. The idea behind it: In a Sharepoint site - in a document library - we are having to many files named BTL_STOCK28732846 BTL_STOCK2873284fd BTL_STOCK287328464 BTL_STOCK28732867u and so one... exported from a software tool that we are using. So we do not need all those files but one. And this will be...
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
“Create a new Java Project” Project name = Lab3 “Use project folder as root for sources...
“Create a new Java Project” Project name = Lab3 “Use project folder as root for sources and class files” Finish Set your classpath for the workspace: Project > Properties > Java Build Path Libraries Add External Jars # if on Windows Choose algs4.jar and stdlib.jar from your user directory Documents/alg4 # else Choose algs4.jar and stdlib.jar from ~/alg4 (I hope you’re getting familiar with this sequence. From now on, I’ll just say “create new project LabX”, and you’ll need to...
Create x empty files in a given directory (x is a number), following a naming format...
Create x empty files in a given directory (x is a number), following a naming format like this: myfile1, myfile2, etc. Ask the user to enter the first part file name and the number of files he/she wants to create. Hint: you may use the “touch” command to quickly create empty files. Take two screenshots: a) Display the source code in an editor (#4-13) b) Execute your script in the terminal, and display the command and the result (#4-14)
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word...
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word " STREET" to the address, for all who live on 2nd or 3rd. For example: "2nd" becomes "2nd STREET" and "3rd" becomes "3rd STREET". Display only the first 9 lines. Hint: Use 2 sed statements with pipes. Task C Display all lines in famous.dat that end in 0 or 1, and have a 1 in the 3rd from the last column. For example lines...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT