Lab Scripting 1 - echadbourne/ChadbourneSYS-140 GitHub Wiki

Summary:

  • In this lab we looked at PowerShell in Windows, and how we can run scrips to do things using this program. We used a few commands, which will be listed below, but we were able to retrieve the file hash of a file, and run various scripts that we saved with the ".ps1" format, which is the format for PowerShell scripts. In order to run one of these scrips, we would have to type the full document location, like so: C:\Users\elizabeth.chadbourne\Desktop\get-date.ps1. We also created a scraping script (scraping is pulling all of the links and information out of a website) and examined websites that it worked on, and websites that it didn't as well as why a website may not allow scraping.

Useful Commands:

  • Get-Filehash - Get the file hash of a given file (requires the full filepath)
  • test-path - tests if the given filepath is valid
  • The scraping script we used (called scrape.ps1 for the lab):

param([string]$a)

$SiteAddress = $a

$HttpContent = Invoke-WebRequest -URI $Site Address

HttpContent.Links | Foreach {$_.href}

(To use this you would have to put the filepath, then the name of the website you wanted scraped in quotations after it, like so: C:\users\elizabeth.chadbourne\desktop\scrape.ps1 "google.com")