Question

i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and Report Search Report host path date Execution time nnn Directories n, nnn, nnn Files nnnnnnn Sym

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Summary :

Pasted below powershell script and output .

Note : Tested with sample

######################### PowerShell script #######################


# Read command line argument .
# if not found

$start_time = (GET-DATE)
if ($args.count -ne 1) {
   Write-Host "Usage scrpt.ps1 <PATH> "
   exit(0)
   }
$path = $args[0]


# Check if input param is valid path

if (-Not (Test-Path $path)) {
   Write-Host "Please check Input param as no entries found under "
   exit(0)
   }

#
#   Get all entries files in given folder
$files = Get-ChildItem -Path $path -ErrorAction Stop -recurse

$num_files = 0
$num_directories = 100000
$num_symlinks = 0
$num_files_older_than_365_days =0
$num_large_files = 0
$num_graphic_files = 0
$num_executable_files = 0
$num_temp_files = 0
$total_byte_count = 0


$slash = '\'

foreach ( $file in ($files ) ) {

   $file_fullpath = $file.FullName
  
   if ( ((Get-Item -Path $file_fullpath -ErrorAction Stop ) -is [System.IO.DirectoryInfo] )) {
       $num_directories = $num_directories + 1
   } else {
       $num_files = $num_files + 1
          
       if ( ($file_fullpath -Like "*.jpg") -or ($file_fullpath -Like "*.gif") -or ($file_fullpath -Like "*.bmp")) {
               $num_graphic_files = $num_graphic_files + 1
       }
      
       if ( ($file_fullpath -Like "*.bat") -or ($file_fullpath -Like "*.ps1") -or ($file_fullpath -Like "*.exe")) {
               $num_executable_files = $num_executable_files + 1
       }
      
       if ( ($file_fullpath -Like "*.o") ) {
               $num_temp_files = $num_temp_files + 1
       }
      
   }
   if ((Get-Item -Path $file_fullpath ).LinkType -eq "SymbolicLink" ) {
           $num_symlinks = $num_symlinks + 1
   }
      
   $len = (Get-Item -Path $file_fullpath ).length
  
  
   if ( $len -gt 500000 ) {
       $num_large_files = $num_large_files + 1
   }
  
   $file_created_date = (Get-Item -Path $file_fullpath).CreationTime
  
   if ( ($start_time - $file_created_date).Days -gt 365 ) {
       $num_files_older_than_365_days = $num_files_older_than_365_days + 1
       }
  
  
   $total_byte_count = $total_byte_count + $len

}

$end_time = (GET-DATE)
$exection_time = ($end_time - $start_time )

$todate = (Get-DATE -DisplayHint date)

Write-Host "Search Report " $env:computername $path $todate.ToString("yyyy-MM-dd")
Write-Host "Execution time " $exection_time.ToString("ss")
Write-Host "Directories " $num_directories.ToString('N0')
Write-Host "Files    " $num_files.ToString('N0')
Write-Host "Sym Links " $num_symlinks.ToString('N0')
Write-Host "Old files " $num_files_older_than_365_days.ToString('N0')
Write-Host "Large files " $num_large_files.ToString('N0')
Write-Host "Graphic files " $num_graphic_files.ToString('N0')
Write-Host "Executable files " $num_executable_files.ToString('N0')
Write-Host "Temporary files " $num_temp_files.ToString('N0')
Write-Host "TotalFileSize " $total_byte_count.ToString('N0')

#######################End of PowerShell Script ####################

##################### Output ########################################

PS I:\PRJ> .Iscrpt.ps1 I: Search Report DESKTOP-VUM526N I: 2020-03-10 Execution time 03 Directories 100, 129 Files 1,807 Sym

####################### End of Output #####################################

Add a comment
Know the answer?
Add Answer to:
i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a...

    Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a shell file called by (your name), your enrollment number, your program and the courses you study. Use the appropriate variables and display the above to the standard output (screen). . 2. Write A Shell Script to perform the following: Display the files and directories Print the date in 24 hour format Display the System id Display the current working directory Print the status of...

  • need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu...

    need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu VM (virtual machine), using terminal mode ONLY, do the following: Create the folder program2 In this folder place the text file located on my faculty website in Module 2 called RAMerrors (Do not rename this file, it has no extension.) It is down below. Ths is the file RAMErrors 3CDAEFFAD ABCDEFABC 7A0EDF301 1A00D0000 Each record in this file represents the location of an error...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • I need this in C++. This is all one question. Introduction Your eighth assignment will consist...

    I need this in C++. This is all one question. Introduction Your eighth assignment will consist of two programs, which will involve the use of simple classes. The source code for these problems should be submitted using the naming conventions we specified in class. Please note that your computer programs should comply with the commenting and formatting rules as described in class. For example, there should be a header for the whole program that gives the author's name, class name,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT