Question

In: Computer Science

Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: You are...

Using PowerShell ISE or VSCode, create a PowerShell script that will do the following:

You are going to create an HTML web page report from a standard processed report. You will use the text file “STUDENTS.TXT” located on Canvas.

The script must meet the following requirements:

  1. The output file should be named ITS3410-{your name}.htm
  2. Every line of data that has a student number (9999-9999) must be included in the report
  3. All data must be trimmed
    1. No leading white space
    2. No trailing white space
    3. No empty values
    4. No garbage lines
  4. The student number MUST be detected using regular expression (regex)
  5. You must include comments in your code to explain it
  6. The report headers must be visible in the HTML web page

Solutions

Expert Solution

What we need to accomplish?

  • To process the input list of text
  • To prepare structured html report based on data in input

Now we can apply the Henry Ford method to these basic tasks ('Every task is simple if split into sufficiently small steps'):

  • Remove unnecessary content from input (remove craplines, clean up important lines)
  • Detect the structure of the content (That will especially require you to interpret the header)
  • Applying knowledge of the structure to parse the data content (hint: The output should be objects)

I have used PowerShell to create the script and to check it by executing the script.

#Input and Output Files


$inputFile = Get-Content c:\users\sharp\desktop\STUDENTS.txt     #getting input file
$output_file = ‘c:\users\sharp\desktop\ITS3410-praveen.htm’         #to get the output file


$FileLine = @()
Foreach ($Line in $inputFile) {
$MyObject = New-Object -TypeName PSObject

#adding the objects

Add-Member -InputObject $MyObject -Type NoteProperty -Name Student# -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name LAST -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name FIRST -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name DN -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name ERN -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name HR -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name STS -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name DEG -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name CON -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name VER -Value $Line
Add-Member -InputObject $MyObject -Type NoteProperty -Name GPA -Value $Line

$FileLine += $MyObject
}

#to convert the script into html
$FileLine | ConvertTo-Html -Property Student#, LAST, FIRST, DN, ERN, HR, STS, DEG, CON, VER, GPA -body "<H2>Student Report</H2>" | Out-File $output_file

Invoke-Expression $output_file

$line = "9999-9999  PRAVEEN KUMAR N  85 12     4       CER CSC      2007A          2.68"
$strings = $line -split " " | Where-Object { $_ }
# Bulk add properties
$props = @{
               StudentID = $strings[0]
               Surname =   $strings[1]
               Firstname = $strings[2]
               DN = $strings[3]
               ERN = $strings[4]
               HR = $strings[5]
               STS = $strings[6]
               DEG = $strings[7]
               CON = $strings[8]
}

# Add more properties by name
$props["VER"] = $strings[9]
$props["GPA"] = $strings[10]
 
# Build Object
New-Object PSObject -Property $props

This method is useful to keep in mind as it is a highly flexible method you will be able to apply in many scenarios.

As for working with strings (which we'll need to do lots of times), we can try running this on the console:

"foo" | gm

This will list us all properties and methods of the string class. We can check out the method names - lots of useful utility there.

Regular Expression (regex) for the Student Number to be recognized:

$str = (Get-Content ... -Raw) -replace '\r'
$cb = {
  $args[0].Groups[1].Value -replace '(?m)^.{7}' -replace '(?m).(.{3}).{5}$', '$1'
}
$re = [regex]'(?m)^(?<=-\n)((?:\d{4}\s\d{2}[^\n]*\d{5}(?:\n|$))+)'
$re.Replace($str, $cb)

Related Solutions

Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions to get the following information Local username Local machine name Time zone Current Date Output the data that was collected to the screen Upload the script. Paste a screenshot of the results here
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import...
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import the users into your domain controller. The user file has a first name, last name, and department. Using this information, create users with the following specifications: Username will be first name.last name User Principal Name will be first name.last [email protected] The department signifies the OU that the user will be placed into If the department does not exist, create it Fill in the first...
1. How to create a group of users using a PowerShell script. 2. how to create...
1. How to create a group of users using a PowerShell script. 2. how to create a file consisting a group of 3 new user name’s and passwords, 1 to a line in power shell. 3. How to write a script in power shell to delete specific group of users. Prove that it works.
Write a Powershell script to create a Windows user account that is a non-admin user. This...
Write a Powershell script to create a Windows user account that is a non-admin user. This assignment assumes that you already have a Windows VM, with the administrator account created.. To complete the assignment, write the PowerShell script, run it on your VM, and submit the script here.
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script that verifies the 'System' environmentvariable, 'LM_LICENSE_FILE', exists. If it exists, the scriptshould also verify that the variable [email protected] (which represents the port and server theLM points to) as one of the values in the variable. Values (if anyare present) are separated by commas "," in this variable. Finally,if the value does not exist, this script should also performremediation (add the desired value to the...
Windows PowerShell 1) Write a PowerShell Script to monitor a file for changes. 2) Write a...
Windows PowerShell 1) Write a PowerShell Script to monitor a file for changes. 2) Write a PowerShell Script to create a user account in a specific OU.
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
Hi, someone please do every part. I'm desperate!! :( Using RStudio, Create an R-Script: (1) You...
Hi, someone please do every part. I'm desperate!! :( Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
Use a powershell script to bulk create 10 users (sales1, sales2, ...) inside OU=MyBusiness, OU=Users, OU=Sales,...
Use a powershell script to bulk create 10 users (sales1, sales2, ...) inside OU=MyBusiness, OU=Users, OU=Sales, save script to desktop
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT