Powershell: Sample for Download Files from an HTTP page

Import-Module BitsTransfer $emailFileList = “” $destinationFolder = “E:\DestTest\” $uri = “https://test.com/test/test/” $hrefs = (invoke-webrequest -Uri $uri).links.innerText $existingFolder = “E:\ExistingFolder” $existingFiles = Get-ChildItem -Path $existingFolder $download = $true foreach ($href in $hrefs) { $download = $true foreach ($existingFile in $existingFiles) { if ($href -eq $existingFile.Name) { $download = $false } }…

Continue reading

Powershell: Read links in an HTTP page and download all the links

Read the links in an HTTP page $url = “http://mirror.internode.on.net/pub/test/10meg.test” $output = “$PSScriptRoot\10meg.test” $start_time = Get-Date Invoke-WebRequest -Uri $url -OutFile $output Download Files with System.Net.WebClient $url = “http://mirror.internode.on.net/pub/test/10meg.test” $output = “$PSScriptRoot\10meg.test” $start_time = Get-Date $wc = New-Object System.Net.WebClient $wc.DownloadFile($url, $output) #OR (New-Object System.Net.WebClient).DownloadFile($url, $output) Write-Output “Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)” Download…

Continue reading

Powerscript: How to Get your Public IP Address

For some reason, you want to write a small script to grab your public IP address and email it to you.  Here is one! $SiteAddress = “http://icanhazip.com” $HttpContent = Invoke-WebRequest -URI $SiteAddress ############################################################### $From = “test@gmail.com” $To = “receipient@gmail.com” $Cc = “receipient2@gmail.com” $Attachment = “C:\temp\Some random file.txt” $Subject = “Email…

Continue reading

HOW TO: Delete Unused User Profile in Windows 7

This script will requires Windows Power Shell version 3 #requires -version 3.0 #Remove-UserProfile.ps1 [cmdletbinding(SupportsShouldProcess)] Param( [Parameter(Position=0)] [ValidateNotNullorEmpty()] [int]$Days=30 ) Function isException($Foldername) { Switch($Foldername) { “C:\Users\All Users” { $True} “C:\Users\Default User” { $True } “C:\Users\Default” { $True } “C:\Users\LocalService” { $True } “C:\Users\NetworkService” { $True } “C:\Users\Administrator” { $True } “C:\Users\Administrator.SAO13″…

Continue reading

PowerShell: Replacing Files

This script will help to search for all sub-directories of the path and replace with your new file. You will need to enter a full Path $logfile.  For example: C:\log.txt $filename can be entered with wildcard.  For example: *Hello*.txt “`n” write-Host “———————————————” -ForegroundColor Yellow $filePath = Read-Host “Please Enter File…

Continue reading