Sunday, August 17, 2014

Bored?

The below script with go through a list of PowerShell links and open them each up one at a time within a single tab. Every 2 seconds a new article will appear -- when you find something good just hit [CTRL]+C to stop the script form continuing.



001
002
003
004
005
006
007
008
009
010
011

$blog="http://www.matthewkerfoot.com/p/powershell-links.html"
$ie = new-object -com internetexplorer.application
$iwr = Invoke-WebRequest -Uri $blog
$links = $iwr.Links | Select-Object -skip 7 -ExpandProperty href
foreach($l in $links){
                        $ie.visible=$true
                        $ie.navigate("$l")
                                while ($ie.Busy -eq $true){ 
                                                            Wait-Event -Timeout 2
                                }
}

Tuesday, August 12, 2014

Easiest way to create a lot of AD accounts.


If $number is an array from 1 to 300 and for every number or $n we run New-ADUser -name $n were going to get 300 users with names like 1, 2 , 3, 4..300.

001
002
003
004
005
006
PS C:\> 1..5 # sample Array
1
2
3
4
5

001
002
003
004
$number = 1..300
foreach ($n in $number){
New-ADUser -name $n -verbose
}


Monday, August 11, 2014

Start a Google search from within a PowerShell Console

Here is what I like to call a little fun function, this function allows you to easily search www.google.com for anything your heart desires. By default it will search for "The Overnight Admin" unless you specify with the -Search parameter like I did as an example on line 34.

The reason that just typing Start-Google at will search for "The Overnight Admin" is because within the param block I've set the $Search parameter to equal the "The Overnight Admin", but if you type Start-Google -Search "powershell" that will overwrite the $Search parameter and open the Google search page for powershell.


001
002
003
004
005
param ([Parameter(Mandatory=$false,
                  ValueFromPipelineByPropertyName=$true,
                  Position=0)]
                  $Search = "The Overnight Admin"
)


Enjoy!

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
Function Start-Google
{
<#
.Synopsis
Searches the Googes
.DESCRIPTION
Lets you quickly start a search Google from within Powershell
.EXAMPLE
Start-Google -search PowerShell
#>

                      [CmdletBinding()]
              Param ( [Parameter(Mandatory=$false,
                      ValueFromPipelineByPropertyName=$true,
                      Position=0)]
                      $Search = "The Overnight Admin",
                      [Parameter(Mandatory=$false,
                      ValueFromPipelineByPropertyName=$true,
                      Position=0)]
                      $google = "https://www.google.com/search?q="
              )
         Begin {
                    $ie = new-object -com internetexplorer.application
         }
    Process {
                $Search | ForEach-Object { $google = $google + "$_+"}
    }
 End
     {
         $url = $google.Substring(0,$google.Length-1)
         $ie.navigate( $url )
         $ie.visible = $true
 }
}
Start-Google -Search "Enter Hilarious Search Here"