├── API └── POSTRequest.ps1 ├── Cmdlets ├── BasicGetContentCmdlet.ps1 ├── BasicGetMemberCmdlet.ps1 ├── ConvertToFromJson.ps1 ├── GetHost.ps1 ├── GetHotFix.ps1 ├── OutPrinter.ps1 ├── ReadHost.ps1 ├── SendMailMessage.ps1 └── TestPath.ps1 ├── Concepts ├── DynamicBatchToRunPowershell.bat ├── OddOREvenNumber.ps1 ├── RedirectingConsoleOutput.ps1 └── StoreScriptConfigDataExternally.ps1 ├── DotNet └── WebClient.ps1 ├── Errors └── BasicTryCatch.ps1 ├── Excel └── WorkbooksAndWorksheetsExcel.ps1 ├── Fun ├── CompareGetHelpAndGetCommandParams.ps1 ├── CountSheep.ps1 ├── MouseShaker.ps1 └── PowershellPet.ps1 ├── Functions └── PassingParamsToFunctions.ps1 ├── Help └── CommentBasedHelp.ps1 ├── Loops ├── DoWhile.ps1 └── ForEach.ps1 ├── Modules ├── BulkHoot │ └── BulkHoot.psm1 ├── RedditNinja │ └── RedditNinja.psm1 └── TwitterNinja │ └── TwitterNinja.psm1 ├── Outlook └── SendEmailFromOutlook.ps1 ├── Pipelining ├── PipeliningGetProcessColoredOutput.ps1 └── PipeliningVariables.ps1 ├── Printers └── InstallDirectIPPrinter.ps1 ├── README.md ├── Reports ├── AdvancedHTMLReport.ps1 ├── DynamicHTMLReport.ps1 └── GetProcessWebReport.ps1 ├── Strings ├── BasicQuotes&SpecialCharacters.ps1 └── ReplaceStringInAFileorFiles.ps1 ├── Tools ├── AdminLaunch.bat ├── BasicRegistry.ps1 ├── ChoiceUI.ps1 ├── CreateShortcut.ps1 ├── DiscoverUSBStorage.ps1 ├── FindPathOfScriptFromScript.ps1 ├── Get-RemoteUserProfile.ps1 ├── HashFromFilesInFolderRecursive.ps1 ├── IMGBurnEXESyntax.txt ├── MountVHD.ps1 ├── PowershellStartUpParameters.bat ├── RestorePoints.ps1 ├── ValidateIPAddress.ps1 └── WMI.ps1 └── Variables ├── CompareAgainstType.ps1 ├── EnvironmentVariables.ps1 ├── ExitCode.ps1 ├── ReservedVariables.ps1 └── VariablesInPowershell.ps1 /API/POSTRequest.ps1: -------------------------------------------------------------------------------- 1 | $URL = "https://api.github.com" 2 | $Endpoint = "/gists" 3 | 4 | $URLAnon = "$URL$Endpoint" 5 | 6 | 7 | $JSON = ConvertTo-Json @{ 8 | description = "the description for this gist"; 9 | public = $true; 10 | files = @{ 11 | "file1.txt" = @{ 12 | content = "String file contents" 13 | } 14 | } 15 | } 16 | 17 | 18 | $gist = Invoke-RestMethod -Method Post -Uri $URLAnon -Body $JSON 19 | 20 | $Token = "?access_token=92a3af3c5ebc6afbfc0018db3215a490058b8537" 21 | $URLSecure = "$URL$Endpoint$Token" 22 | 23 | $gist = Invoke-RestMethod -Method Post -Uri $URLSecure -Body $JSON 24 | 25 | $URLEdit = "$URL$Endpoint/$($gist.id)$Token" 26 | 27 | $JSON2 = ConvertTo-Json @{ 28 | description = "Potato"; 29 | public = $true; 30 | files = @{ 31 | "file1.txt" = @{ 32 | content = "I'm Hungry" 33 | } 34 | } 35 | } 36 | 37 | $gist = Invoke-RestMethod -Method Post -Uri $URLEdit -Body $JSON2 38 | -------------------------------------------------------------------------------- /Cmdlets/BasicGetContentCmdlet.ps1: -------------------------------------------------------------------------------- 1 | $File = "" 2 | $Text = "" 3 | 4 | 5 | $Content = Get-Content $File 6 | 7 | $Content | Foreach { 8 | 9 | if ($_ -ilike "$Text") {Write-Output $_} 10 | 11 | } -------------------------------------------------------------------------------- /Cmdlets/BasicGetMemberCmdlet.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | #Using get member to find out information about the get-process cmdlet 4 | Get-Process | Get-Member 5 | 6 | #after finding out the Get-Process Cmdlet has a Company property we can use it with other Cmdlets to refine results 7 | Get-Process | Sort-Object Company | Where {$_.Company -ne $Null} 8 | 9 | $Variable = "String" 10 | 11 | #finding more information about our variable with Get-Member 12 | $Variable | Get-Member 13 | 14 | #Using the ToLower() method to change the characters in our string to lower case 15 | $Variable.ToLower() -------------------------------------------------------------------------------- /Cmdlets/ConvertToFromJson.ps1: -------------------------------------------------------------------------------- 1 | #Create a JSON object model from Get-Process 2 | Get-Process | ConvertTo-Json | Out-File C:\SomeFolder\SomeFile.txt 3 | 4 | #Download JSON model of the Reddit front page, and load it as a powershell object 5 | $WebClient = New-Object net.webclient 6 | 7 | $Json = $WebClient.Downloadstring("http://www.reddit.com/.json") | ConvertFrom-Json 8 | 9 | 10 | $Keys=@() 11 | (0..($Json.data.children.count-1)) | ForEach-Object { 12 | 13 | $Keys+= @{ 14 | "title"=$Json.data.children.Item($_).data.title 15 | "url"=$Json.data.children.Item($_).data.url 16 | "PermaLink"=$Json.data.children.Item($_).data.permalink 17 | "score"=$Json.data.children.Item($_).data.score 18 | "ups"=$Json.data.children.Item($_).data.ups 19 | "downs"=$Json.data.children.Item($_).data.downs 20 | "author"=$Json.data.children.Item($_).data.author 21 | "Num_Comments"=$Json.data.children.Item($_).data.num_comments 22 | "over_18"=$Json.data.children.Item($_).data.over_18 23 | "subreddit"=$Json.data.children.Item($_).data.subreddit 24 | "domain"=$Json.data.children.Item($_).data.domain 25 | "banned_by"=$Json.data.children.Item($_).data.banned_by 26 | "media_embed"=$Json.data.children.Item($_).data.media_embed 27 | "selftext_html"=$Json.data.children.Item($_).data.selftext_html 28 | "selftext"=$Json.data.children.Item($_).data.selftext 29 | "likes"=$Json.data.children.Item($_).data.likes 30 | "saved"=$Json.data.children.Item($_).data.saved 31 | "clicked"=$Json.data.children.Item($_).data.clicked 32 | "approved_by"=$Json.data.children.Item($_).data.approved_by 33 | "hidden"=$Json.data.children.Item($_).data.hidden 34 | "thumbnail"=$Json.data.children.Item($_).data.thumbnail 35 | "subreddit_id"=$Json.data.children.Item($_).data.subreddit_id 36 | "author_flair_css_class"=$Json.data.children.Item($_).data.author_flair_css_class 37 | "is_self"=$Json.data.children.Item($_).data.is_self 38 | "name"=$Json.data.children.Item($_).data.name 39 | "id"=$Json.data.children.Item($_).data.id 40 | "created"=$Json.data.children.Item($_).data.created 41 | "author_flair_text"=$Json.data.children.Item($_).data.author_flair_text 42 | "created_utc"=$Json.data.children.Item($_).data.created_utc 43 | "media"=$Json.data.children.Item($_).data.media 44 | "num_reports"=$Json.data.children.Item($_).data.num_reports 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /Cmdlets/GetHost.ps1: -------------------------------------------------------------------------------- 1 | Get-Host 2 | 3 | 4 | $Ver = Get-Host | Select-Object Version 5 | cls 6 | If ($Ver -imatch "3.0") { Write-Host "This is powershell 3.0!"} 7 | Elseif ($Ver -imatch "2.0") { Write-Host "This is powershell 2.0!" } 8 | Elseif ($Ver -imatch "1.0") { Write-Host "This is powershell 1.0!" } 9 | -------------------------------------------------------------------------------- /Cmdlets/GetHotFix.ps1: -------------------------------------------------------------------------------- 1 | #$HotFixes = Get-HotFix 2 | 3 | <# 4 | foreach ($HotFix in $HotFixes) { 5 | 6 | if ($HotFix.Installedby -ilike "*fern*") { 7 | 8 | Write-Host $Hotfix.HotFixID 9 | } 10 | } 11 | #> 12 | 13 | 14 | <# 15 | $List = $HotFixes.GetEnumerator() | Select-Object -ExpandProperty Hotfixid 16 | 17 | Out-File "$env:HOMEDRIVE\$env:HOMEPATH\desktop\$Env:COMPUTERNAME.txt" -InputObject $List 18 | #> -------------------------------------------------------------------------------- /Cmdlets/OutPrinter.ps1: -------------------------------------------------------------------------------- 1 | #Simple Out-Printer examples 2 | $Stuff = Get-Process 3 | 4 | Out-Printer -InputObject $Stuff -Name $PrinterName 5 | 6 | 7 | Get-Process | Out-Printer 8 | 9 | 10 | #Advanced Out-Printer example 11 | $FileDate = Get-Date -Format "MMMddyy_HHmmss" 12 | $FileName = "DailyReport_$FileDate.txt" 13 | $FilePath = "Path" 14 | $Fullpath = "$FilePath\$Filename" 15 | 16 | New-Item -Name $Filename -Path $Filepath -ItemType File 17 | 18 | 19 | "$env:COMPUTERNAME" | Out-File -FilePath $FullPath -Append 20 | Get-Date -Format "MMM/dd/yyyy HH:mm:ss" | Out-File -FilePath $Fullpath -Append 21 | Get-Service | where {$_.name -ilike "b*" -or $_.name -ilike "w*"} | Format-Table Name, Status | Out-File -FilePath $Fullpath -Append 22 | 23 | Get-Content $FullPath | Out-Printer 24 | 25 | -------------------------------------------------------------------------------- /Cmdlets/ReadHost.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | #Assigns the input to a variable, or remove "$Var=" to pass the input to the pipeline 3 | $Var = Read-Host -Prompt "Please Enter Your Name" -AsSecureString #| Write-Host -ForegroundColor Green 4 | 5 | 6 | 7 | #This code will allow you to convert the secured string back to plain text 8 | #Add "$Var2 =" to the second line of code to add it into a variable 9 | $marshal = [Runtime.InteropServices.Marshal] 10 | $marshal::PtrToStringAuto($marshal::SecureStringToBSTR($Var)) -------------------------------------------------------------------------------- /Cmdlets/SendMailMessage.ps1: -------------------------------------------------------------------------------- 1 | $MyEmail = "PlayingWithPowershell@gmail.com" 2 | $SMTP= "smtp.gmail.com" 3 | $To = "PlayingWithPowershell@gmail.com" 4 | $Subject = "BRO!" 5 | $Body = "WHAT UP MR.POWERSCRIPTS?" 6 | $Creds = (Get-Credential -Credential "$MyEmail") 7 | 8 | Start-Sleep 2 9 | 10 | Send-MailMessage -To $to -From $MyEmail -Subject $Subject -Body $Body -SmtpServer $SMTP -Credential $Creds -UseSsl -Port 587 -DeliveryNotificationOption never 11 | 12 | <# 13 | $PSEmailServer variable can be used to pre-configure the 14 | SMTP server in your Powershell Profile. Then you don't need 15 | to specify -smtpserver paramter. Send-MailMessage will use the 16 | SMTP sever address assigned to $PSEmailServer 17 | 18 | 19 | Delivery Notification Options: 20 | -- None: No notification. 21 | -- OnSuccess: Notify if the delivery is successful. 22 | -- OnFailure: Notify if the delivery is unsuccessful. 23 | -- Delay: Notify if the delivery is delayed. 24 | -- Never: Never notify. 25 | #> -------------------------------------------------------------------------------- /Cmdlets/TestPath.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | #Test path returns a true or false result 3 | #Test-Path C:\Users\Fer 4 | 5 | #Use test path within a logic statement 6 | #if (Test-Path C:\users\fer) {Write-Host "The folder exists!"} 7 | 8 | #Check if a path doesn't exist 9 | #if (!(Test-Path C:\users\fer)) {Write-Host "The folder doesn't exist!"} 10 | 11 | #Test the path of a file 12 | #Test-Path -Path C:\Users\Fern\Desktop\Notepad+.lnk 13 | 14 | #Test paths of the registry as well 15 | #Test-Path -Path HKCU:\software\Microsoft 16 | #Test-Path -Path HKCU:\software\Microhard 17 | 18 | #Create a folder if it doesn't exist 19 | <# 20 | if (!(Test-Path C:\users\fern\desktop\test)) { 21 | 22 | New-Item C:\users\fern\desktop\test -ItemType directory 23 | New-Item C:\users\Fern\Desktop\test -Name RandomFile.exe -ItemType file 24 | 25 | New-Item C:\users\fern\desktop\test\testing -ItemType directory 26 | New-Item C:\users\Fern\Desktop\test\testing -Name RandomFile.xls -ItemType file 27 | } 28 | #> 29 | 30 | #Check for specific item type with PathType Parameter 31 | #Get-ChildItem C:\users\fern\Desktop -Filter *.exe 32 | #Test-Path -Path C:\Users\Fern\Desktop\what.exe -PathType leaf 33 | 34 | #Check if specific items exist in folder , or do not exist 35 | #Test-Path C:\users\fern\Desktop\test\* -Exclude *.exe -PathType Leaf 36 | 37 | #Only in powershell 3 38 | #Check if path existed before or after date 39 | 40 | #Test-Path -Path C:\Windows -OlderThan "10/27/2002" -------------------------------------------------------------------------------- /Concepts/DynamicBatchToRunPowershell.bat: -------------------------------------------------------------------------------- 1 | 2 | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass %~dp0%~n0.ps1 3 | -------------------------------------------------------------------------------- /Concepts/OddOREvenNumber.ps1: -------------------------------------------------------------------------------- 1 | $Nums = 8,10,205423,54,234,123,65,342,234,546,234,635,654,23423,23465,5431,2424,432146,345342534532523523,12453,3425,142,23,2342,453,32451,34534,53422,345,24,5432,5425,2345,342234,53,2345,32534,23452,253,2345,25 2 | 3 | <# 4 | 5 % 3 5 | 8 % 4.25 6 | 8 % 2 7 | #> 8 | 9 | 10 | $Nums | ForEach-Object { 11 | 12 | if ($_ % 2 -eq 0) { 13 | 14 | Write-Host "$_ is even!" -f Green 15 | 16 | } else {Write-Host "$_ is odd!" -f Red } 17 | 18 | } -------------------------------------------------------------------------------- /Concepts/RedirectingConsoleOutput.ps1: -------------------------------------------------------------------------------- 1 | $Loc="C:\somefolder\testfile.txt" 2 | $TO="C:\somefolder\testoutput.txt" 3 | 4 | cls 5 | 6 | #Using out-null can supress some kinds of output from Powershell 7 | #New-Item $Loc -ItemType file | Out-Null 8 | 9 | #New-Item $Loc -ItemType file -Force | Out-Null 10 | 11 | 12 | 13 | 14 | 15 | 16 | #You can use the redirection symbol to 17 | #New-Item $Loc -ItemType file > $Null 18 | #New-Item $Loc -ItemType file 2> $TO 19 | #New-Item $Loc -ItemType file 2> $Null 20 | #New-Item $Loc -ItemType file 2>> $TO 21 | #New-Item $Loc -ItemType file 2>&1 | Out-File $TO 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | #Use Tee-Object to redirect the contents of a pipeline to a file/variable 30 | #Then continue handing those contents down the pipeline 31 | Get-Process | Tee-Object -FilePath $Loc | Select-Object ProcessName,CPU | ft -AutoSize 32 | -------------------------------------------------------------------------------- /Concepts/StoreScriptConfigDataExternally.ps1: -------------------------------------------------------------------------------- 1 |  2 | <# 3 | 4 | 5 | Placing values in test.txt like this: 6 | 7 | One=1 8 | Two=2 9 | Three=3 10 | 11 | will allow you to call the values from powershell like this: 12 | 13 | $ConfigKeys.One 14 | $Configkeys.Two 15 | $ConfigKeys.Three 16 | 17 | to display the stored values 18 | 19 | #> 20 | 21 | #File with the stored data 22 | $ConfigFile = "C:\SomeFile\test.txt" 23 | #Creating an empty hash table 24 | $ConfigKeys = @{} 25 | 26 | 27 | #Pulling, separating, and storing the values in $ConfigKey 28 | Get-Content $ConfigFile | ForEach-Object { 29 | 30 | $Keys = $_ -split "=" 31 | 32 | $ConfigKey += @{$Keys[0]=$Keys[1]} 33 | 34 | } -------------------------------------------------------------------------------- /DotNet/WebClient.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $WebClient = New-Object net.webclient 5 | 6 | $Json = $WebClient.Downloadstring("http://www.reddit.com/.json") | ConvertFrom-Json 7 | 8 | 9 | $Keys=@() 10 | (0..($Json.data.children.count-1)) | ForEach-Object { 11 | 12 | $Keys+= @{ 13 | "title"=$Json.data.children.Item($_).data.title 14 | "url"=$Json.data.children.Item($_).data.url 15 | "PermaLink"=$Json.data.children.Item($_).data.permalink 16 | "score"=$Json.data.children.Item($_).data.score 17 | "ups"=$Json.data.children.Item($_).data.ups 18 | "downs"=$Json.data.children.Item($_).data.downs 19 | "author"=$Json.data.children.Item($_).data.author 20 | "Num_Comments"=$Json.data.children.Item($_).data.num_comments 21 | "over_18"=$Json.data.children.Item($_).data.over_18 22 | "subreddit"=$Json.data.children.Item($_).data.subreddit 23 | "domain"=$Json.data.children.Item($_).data.domain 24 | "banned_by"=$Json.data.children.Item($_).data.banned_by 25 | "media_embed"=$Json.data.children.Item($_).data.media_embed 26 | "selftext_html"=$Json.data.children.Item($_).data.selftext_html 27 | "selftext"=$Json.data.children.Item($_).data.selftext 28 | "likes"=$Json.data.children.Item($_).data.likes 29 | "saved"=$Json.data.children.Item($_).data.saved 30 | "clicked"=$Json.data.children.Item($_).data.clicked 31 | "approved_by"=$Json.data.children.Item($_).data.approved_by 32 | "hidden"=$Json.data.children.Item($_).data.hidden 33 | "thumbnail"=$Json.data.children.Item($_).data.thumbnail 34 | "subreddit_id"=$Json.data.children.Item($_).data.subreddit_id 35 | "author_flair_css_class"=$Json.data.children.Item($_).data.author_flair_css_class 36 | "is_self"=$Json.data.children.Item($_).data.is_self 37 | "name"=$Json.data.children.Item($_).data.name 38 | "id"=$Json.data.children.Item($_).data.id 39 | "created"=$Json.data.children.Item($_).data.created 40 | "author_flair_text"=$Json.data.children.Item($_).data.author_flair_text 41 | "created_utc"=$Json.data.children.Item($_).data.created_utc 42 | "media"=$Json.data.children.Item($_).data.media 43 | "num_reports"=$Json.data.children.Item($_).data.num_reports 44 | 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Errors/BasicTryCatch.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | Try { 3 | 4 | [int]$Variable = "asdf" 5 | 6 | 7 | } 8 | 9 | Catch { 10 | 11 | Write-Host "You dun goofed!" 12 | Write-Host $_ 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Excel/WorkbooksAndWorksheetsExcel.ps1: -------------------------------------------------------------------------------- 1 |  2 | #None of this will work through an already open excel application 3 | #You must open Excel and workbooks you want to manipulate via the COMobject 4 | 5 | #################################################### 6 | ############### Starting Excel ##################### 7 | #################################################### 8 | 9 | $Excel = New-Object -ComObject Excel.Application 10 | 11 | $Excel.Visible = $true 12 | $Excel.DisplayAlerts = $false 13 | 14 | #################################################### 15 | ############## Working with Workbooks ############## 16 | #################################################### 17 | 18 | #Add a workbook to your current excel file 19 | #You can add multiple workbooks with this method 20 | $Excel.Workbooks.Add() 21 | 22 | #Find all the workbooks in your excel file by name 23 | $Excel.Workbooks | Select-Object -ExpandProperty name 24 | 25 | #Activate a specifc workbook in your excel file 26 | $Excel.Workbooks.Item(2).activate() 27 | $Excel.Workbooks.Item("book1").activate() 28 | 29 | #Acivate Random Workbook in Excel file 30 | $Excel.Workbooks.Item((Get-Random -min 1 -Max ($Excel.Workbooks.Count+1))).activate() 31 | 32 | #Open an existing workbook on your hardrive 33 | $Excel.Workbooks.Open("$env:userprofile\desktop\mrpowerscripts.xlsx") 34 | 35 | #close workbooks from an excel file 36 | $Excel.Workbooks.Item(1).close() 37 | $Excel.Workbooks.Item("MrPowerScripts.xlsx").close() 38 | 39 | #Save workbooks to the hard drive 40 | $Excel.Workbooks.item(1).SaveAs("$env:userprofile\Desktop\asdf.xlsx") 41 | 42 | 43 | #################################################### 44 | ########### Working with Worksheets ################ 45 | #################################################### 46 | 47 | #These bits of code will affect the active Workbook. 48 | 49 | #Add a worksheet to your active workbook 50 | $Excel.Worksheets.Add() 51 | 52 | #Find all worksheets in your active workbook 53 | $Excel.Worksheets | Select-Object -ExpandProperty name 54 | 55 | #Change name of worksheet in workbook 56 | $Excel.Worksheets.Item(1).name = "potato" 57 | $Excel.Worksheets.Item("potato").name = "spud" 58 | 59 | #Activate specific worksheet in workbook 60 | $Excel.Worksheets.Item(2).activate() 61 | $Excel.Worksheets.Item("sheet3").activate() 62 | 63 | #Acivate Random Worksheet in Excel file 64 | $Excel.Worksheets.Item((Get-Random -min 1 -Max ($Excel.Worksheets.Count+1))).activate() 65 | 66 | #Delete worksheets from workbook 67 | $Excel.Worksheets.Item(1).delete() 68 | $Excel.Worksheets.Item("Sheet3").delete() 69 | 70 | 71 | #################################################### 72 | ########## Cleaning up the environment ############# 73 | #################################################### 74 | 75 | $Excel.Workbooks.Close() 76 | $Excel.Quit() 77 | 78 | #Check and you will see an excel process still exists after quiting 79 | #Remove the excel process by piping it to stop-porcess 80 | Get-Process excel | Stop-Process -Force 81 | 82 | #Now we must release the $excel com object to ready it for garbage collection 83 | [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) 84 | -------------------------------------------------------------------------------- /Fun/CompareGetHelpAndGetCommandParams.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | #Grab all the cmdlets accessible in this session 3 | $Cmdlets = (Get-Command | where {$_.commandtype -eq "cmdlet"} | 4 | select -ExpandProperty name) 5 | 6 | #Run the test all all installed cmdlets 7 | $Cmdlets | foreach { 8 | 9 | #Grab the parameters for this cmdlet via Get-Command 10 | $GetCommandParams = (Get-Command $_).Parameters.keys 11 | 12 | 13 | #Remove common parameters from Get-Command list 14 | $GetCommandParams = $GetCommandParams | 15 | where {$_ -ne "OutBuffer" ` 16 | -and $_ -ne "OutVariable" ` 17 | -and $_ -ne "WarningVariable" ` 18 | -and $_ -ne "ErrorVariable" ` 19 | -and $_ -ne "WarningAction" ` 20 | -and $_ -ne "ErrorAction" ` 21 | -and $_ -ne "Debug" ` 22 | -and $_ -ne "Verbose" ` 23 | -and $_ -ne "WhatIf" ` 24 | -and $_ -ne "Confirm"} 25 | 26 | #Grab parameters mentioned in the get-help file for cmdlet 27 | $GetHelpParams =(Get-Help $_).parameters.parameter | 28 | % {$_ | select -ExpandProperty name} 29 | 30 | #Remove Common Parameters from Get-Help List 31 | $GetHelpParams = $GetHelpParams | 32 | where {$_ -ne "Confirm" ` 33 | -and $_ -ne "WhatIf"} 34 | 35 | #If statemente that prevents errors from null results 36 | if (($GetHelpParams -ne $null) -and ($GetCommandParams -ne $null)) { 37 | 38 | #put the comparision in a variable to use later 39 | $Compare = Compare-Object $GetHelpParams $GetCommandParams 40 | 41 | #If statement to only display results with differences 42 | if ($Compare.count -gt 0) { 43 | #Display the differences between Get-Help and Get-Command params 44 | Write-Host "`n$_" -ForegroundColor Green 45 | $Compare 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Fun/CountSheep.ps1: -------------------------------------------------------------------------------- 1 | $Sheep = 1..100 2 | 3 | <<<<<<< HEAD 4 | $Sheep | ForEach { 5 | 6 | 7 | Write-Host "$Sheep Sheep" 8 | ======= 9 | 10 | Write-Host "$_ Sheep" 11 | >>>>>>> c068304201be0db3b2c300d86b554b817e4be049 12 | 13 | 14 | } -------------------------------------------------------------------------------- /Fun/MouseShaker.ps1: -------------------------------------------------------------------------------- 1 | $Cursor = [system.windows.forms.cursor]::Clip 2 | 3 | #[system.windows.forms.cursor]::Position = New-Object system.drawing.point(0,0) 4 | 5 | #[system.windows.forms.cursor]::Position = New-Object system.drawing.point(($Cursor.Width/2),($Cursor.Height/2)) 6 | 7 | #Must add this line of code for [system.windows.forms.cursor]::Position to work outside of ISE 8 | #Thanks to Meik1988 on youtube for schooling me 9 | [System.Reflection.Assembly]::LoadWithPartialName("system.windows.forms") 10 | 11 | for ($i=1;$i -lt 5000;$i++) { 12 | 13 | $Position = [system.windows.forms.cursor]::Position 14 | 15 | $PositionChange = Get-Random 20 16 | 17 | switch (Get-Random 4) { 18 | 19 | 0 {[system.windows.forms.cursor]::Position = New-Object system.drawing.point($Position.x, ($Position.y + $PositionChange))} 20 | 1 {[system.windows.forms.cursor]::Position = New-Object system.drawing.point(($Position.x + $PositionChange),$Position.y)} 21 | 2 {[system.windows.forms.cursor]::Position = New-Object system.drawing.point($Position.x, ($Position.y - $PositionChange))} 22 | 3 {[system.windows.forms.cursor]::Position = New-Object system.drawing.point(($Position.x - $PositionChange),$Position.y)} 23 | 24 | } 25 | 26 | #$PositionChange 27 | $i 28 | 29 | } 30 | 31 | #> -------------------------------------------------------------------------------- /Fun/PowershellPet.ps1: -------------------------------------------------------------------------------- 1 | #Powershell Pet 2 | 3 | $Move = 10 4 | $Colors = [enum]::GetNames([system.consolecolor]) 5 | 6 | for (;;) { 7 | 8 | $Mover = "" 9 | 10 | switch (Get-Random 5) { 11 | 12 | 0 {break} 13 | 1 {$Move = $Move + 1; break} 14 | 2 {$Move = $Move - 1; break} 15 | 3 {$Move = $Move + 2; break} 16 | 4 {$Move = $Move - 2; break} 17 | } 18 | 19 | for ($i=0; $i -lt $Move; $i++) { 20 | $Mover += " " 21 | } 22 | 23 | switch -Regex (Get-Random 5) { 24 | 25 | [0-1] {break} 26 | [2-4] {$Color = $Colors[(Get-Random 16)]} 27 | } 28 | 29 | cls 30 | 31 | switch (Get-Random 6) { 32 | 33 | 0 {write-host "`n$Mover(>'')>" -ForegroundColor $Color; break} 34 | 35 | 1 {write-host "`n$Mover<(''<)" -F $Color; break} 36 | 37 | 2 {write-host "`n$Mover(V''V)" -F $Color; break} 38 | 39 | 3 {write-host "`n$Mover(^''^)" -F $Color; break} 40 | 41 | 4 {write-host "`n$Mover<( Y )" -F $Color; break} 42 | 43 | 5 {write-host "`n$Mover( Y )>" -F $Color; break} 44 | } 45 | 46 | sleep 1 47 | 48 | } -------------------------------------------------------------------------------- /Functions/PassingParamsToFunctions.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | #Example of passing params to a function with () outside the script block 3 | function Date-Created-Out ($File,$Q) { 4 | 5 | ($FileInfo = Get-ItemProperty -Path $File).creationtime | Out-Host 6 | 7 | if ($Q -imatch "y"){($FileInfo.CreationTime).DayOfYear|Out-Host} 8 | 9 | } 10 | 11 | function Date-Created-In { 12 | 13 | #Example of passing params using param statement inside the script block 14 | #Also showing that defualt params can be set as well as var types 15 | param ($File="C:\winpe", [int]$Q=0) 16 | 17 | ($FileInfo = Get-ItemProperty -Path $File).creationtime | Out-Host 18 | 19 | if ($Q -eq 1) {($FileInfo.CreationTime).DayOfYear|Out-Host} 20 | 21 | } 22 | 23 | function Date-Created-Args { 24 | 25 | #Example of grabbing parameters using the $Args reserved variable 26 | $File = $args[0];$Q = $args[1] 27 | 28 | ($FileInfo = Get-ItemProperty -Path $File).creationtime | Out-Host 29 | 30 | if ($Q -imatch "y"){($FileInfo.CreationTime).DayOfYear|Out-Host} 31 | } 32 | 33 | 34 | #Method with ($Args) on the outside of {} 35 | Date-Created-Out -q n -File "C:\Windows" 36 | 37 | #Method using Param () as the first set of code inside {} 38 | Date-Created-In -Q 1 39 | 40 | #Method using the special $Args variable and [] to select 41 | Date-Created-Args "C:\users\Fern" -------------------------------------------------------------------------------- /Help/CommentBasedHelp.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | function Show-Help { 5 | <# 6 | 7 | .synopsis 8 | Shows how to add comment based help to a script 9 | 10 | .description 11 | A file that doesn't really do much, but does how how to add 12 | 13 | comment based help to Powershell Scripts and functions! 14 | 15 | #> 16 | 17 | Param ($test) 18 | 19 | Get-Process 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Loops/DoWhile.ps1: -------------------------------------------------------------------------------- 1 | do {$i++; write-host $i; } while ((Test-Path "$Folder") -eq $True) -------------------------------------------------------------------------------- /Loops/ForEach.ps1: -------------------------------------------------------------------------------- 1 | #ForEach Pipelining 2 | Get-Service | ForEach { 3 | 4 | if ($_.status -imatch "running") {Write-Host $_ -ForegroundColor Green} 5 | if ($_.status -imatch "stopped") {Write-Host $_ -ForegroundColor Red} 6 | 7 | } 8 | 9 | #ForEach without pipelining 10 | $Services = Get-Service 11 | 12 | ForEach ($Potato in $Services) { 13 | 14 | if ($Potato.status -imatch "running") {Write-Host $Potato -ForegroundColor Green} 15 | if ($Potato.status -imatch "stopped") {Write-Host $Potato -ForegroundColor Red} 16 | 17 | } 18 | 19 | #ForEach example to delete files with a certain extension recursively 20 | 21 | $Stuff = Get-ChildItem $Folder -Recurse 22 | 23 | 24 | Foreach ($Item in $Stuff) { 25 | 26 | $Parent = $Item.DirectoryName 27 | 28 | 29 | if ($item.Extension -ilike ".php") {Remove-Item "$Parent\$Item" } 30 | 31 | 32 | } -------------------------------------------------------------------------------- /Modules/BulkHoot/BulkHoot.psm1: -------------------------------------------------------------------------------- 1 | function New-BulkHoot { 2 | <# 3 | 4 | .SYNOPSIS 5 | Creates Bulk HootSuite File 6 | 7 | .DESCRIPTION 8 | New-BulkHoot allows you to create various types of blank HootSuite CSV files for uploading to HootSuite.com and automating your Twitter feed 9 | 10 | .PARAMETER BulkPath 11 | Specifies a path and filename to send the generated file to 12 | 13 | .PARAMETER TweetInterval 14 | Specifies time in minutes to space between Tweets. Value must end with 0 or 5. 15 | 16 | .PARAMETER Limit 17 | Set the limit of lines to generate in the file. Maximum limit is 50 set by HootSuite. 18 | 19 | .Parameter IncludeTime 20 | Includes an timestamp in the generated file starting 20 minutes from the time it's run. This timestamp specifies when scheduled tweets will be sent out. By default using this parameter will only generate enough scheduled tweets for the same day, which depends on the time when run, TweetInterval, and limit. Use -IgnoreDayChange with -IncludeTime to continue generating max scheduled tweets past current day 21 | 22 | .PARAMETER IgnoreDayChange 23 | Must be used with -IncludeTime. Allows you to generate tweets for the same day into the next day. 24 | 25 | .PARAMETER NewDay 26 | Must be used with -IncludeTime. Creates a new file for the specified date starting from midnight, and increments every 30 minutes. 27 | 28 | .PARAMETER SetDate 29 | Must be used with -NewDay. Provide a date in the format MM/dd/yyyy to create a new file that starts from midnight and increments every 30 minutes for a full day of tweets for that day. 30 | 31 | .EXAMPLE 32 | New-BulkHoot -BulkPath $Path 33 | Will create a new BulkUpload to the path provided with 50 lines of "","","". If no path is provided the CSV will be saved to your desktop with a current timestamp 34 | 35 | .EXAMPLE 36 | New-BulkHoot -TweetInterval 10 37 | Default Time Increment between tweets is 30 minutes. You can change the increment value between 10 or more minutes apart. Value must end in 0 or 5. Remember you are limited to only 50 lines per upload! 38 | 39 | .EXAMPLE 40 | New-BulkHoot -Limit 40 41 | Limits the number of lines which are exported to the file. You can limit the file between 1 and 49 lines. Remember you are limited to only 50 lines per upload! 42 | 43 | .EXAMPLE 44 | New-BulkHoot -IncludeTime 45 | Will create a new BulkUpload to your desktop with the date and time filled out up to 50 lines or until the end of the current day. Such as "01/23/2045 12:35","","". This parameter by default generates timestamps 20 minutes ahead of the current time. 46 | 47 | .EXAMPLE 48 | New-BulkHoot -IncludeTime -IgnoreDayChange 49 | Creates a new file of up to 50 lines with date included, such as "01/23/2045 12:35","","", and does not stop generating lines when a new day begins. 50 | Without this parameter -IncludeTime will only generate enough lines for the current day - depending on current time of day, the limit and incrememnt. 51 | 52 | .EXAMPLE 53 | New-BulkHoot -IncludeTime -NewDay 54 | Creates a new file for the next day starting from midnight, and by default increments every 30 minutes. This provides the framework for a full day of tweets every half hour. 55 | 56 | .EXAMPLE 57 | New-BulkHoot -IncludeTime -NewDay -SetDate 12/31/2012 58 | Creates a new file for the specified date starting from midnight, and by default increments every 30 minutes. This provides the framework for a full day of tweets every half hour. -SetDate must be used with -Newday parameter. 59 | 60 | .LINK 61 | www.youtube.com/MrPowerScripts 62 | 63 | #> 64 | [cmdletbinding()] 65 | 66 | param ( 67 | 68 | [string]$BulkPath, 69 | 70 | [switch]$IncludeTime, 71 | 72 | [switch]$IgnoreDayChange, 73 | 74 | [int]$TweetInterval=30, 75 | 76 | [string]$SetDate, 77 | 78 | [switch]$NewDay, 79 | 80 | [ValidateRange(0,50)] 81 | [int]$Limit=50 82 | 83 | ) 84 | 85 | $Counter = 0 86 | #Start time this many minutes in the future 87 | $Minutes = 20 88 | $Lines = "" 89 | $CurLine = "" 90 | 91 | #If no path provided send to desktop 92 | if (!$BulkPath) {$BulkPath = "$env:USERPROFILE\desktop\BulkHoot$(Get-Date -Format MMddyyyy_HHmmss).csv"} 93 | 94 | #How to validate the end of an integer when you failed at using only regex 95 | $TweetIntervalCheck = $TweetInterval.ToString() 96 | if ($TweetIntervalCheck[-1] -inotmatch "[05]") {throw "-TweetInterval must end in 0 or 5"} 97 | 98 | 99 | if ($SetDate) { 100 | 101 | try { 102 | $SetDate = get-date ("$SetDate" -as [datetime]) -format MM/dd/yyyy 103 | } catch {Throw "Date not valid - use format MM/dd/yyyy"} 104 | } 105 | 106 | if ($IncludeTime) { 107 | 108 | if ($NewDay) { 109 | $CurDay = (Get-Date).adddays(1).day} else {$CurDay = (Get-Date).day 110 | } 111 | 112 | $TimeMap = [datetime]::ParseExact((Get-Date -Format "ddMMyyyy HH:mm"),”ddMMyyyy HH:mm",$null) 113 | 114 | switch ($TimeMap.Minute.ToString().length) { 115 | 116 | 1 {$MinuteChanger = ($TimeMap.Minute).ToString().substring(0,1)} 117 | 2 {$MinuteChanger = ($TimeMap.Minute).ToString().substring(1,1)} 118 | } 119 | 120 | #adjust minute column to 0 121 | switch ($MinuteChanger) { 122 | 123 | 1 {$TimeMap = $TimeMap.AddMinutes(9)} 124 | 2 {$TimeMap = $TimeMap.AddMinutes(8)} 125 | 3 {$TimeMap = $TimeMap.AddMinutes(7)} 126 | 4 {$TimeMap = $TimeMap.AddMinutes(6)} 127 | 6 {$TimeMap = $TimeMap.AddMinutes(4)} 128 | 7 {$TimeMap = $TimeMap.AddMinutes(3)} 129 | 8 {$TimeMap = $TimeMap.AddMinutes(2)} 130 | 9 {$TimeMap = $TimeMap.AddMinutes(1)} 131 | } 132 | } 133 | 134 | if ($NewDay) {$Minutes = 0} 135 | $TimeCheck = $CurDay 136 | 137 | do { 138 | 139 | $CurLine = "" 140 | 141 | if ($IncludeTime) { 142 | 143 | if ($NewDay) { 144 | 145 | $Timemap = $TimeMap.Date 146 | Write-Debug "TimeMap: $TimeMap" 147 | 148 | if (!$IgnoreDayChange) { 149 | $TimeCheck = ($TimeMap.AddMinutes($Minutes).adddays(1)).day 150 | Write-Debug "TimeCheck: $TimeCheck" 151 | } else {$TimeCheck = $CurDay} 152 | 153 | if ($TimeCheck -eq $CurDay){ 154 | $CurLine += "`"" + (Get-Date ($TimeMap.AddMinutes($Minutes).adddays(1)) -Format "MM/dd/yyyy HH:mm").tostring().substring(0,16)+"`",`"`",`"`"`n" 155 | Write-Debug "CurLine: $CurLine" 156 | } 157 | 158 | } else { 159 | 160 | if (!$IgnoreDayChange) { 161 | $TimeCheck = ($TimeMap.AddMinutes($Minutes)).day 162 | } else {$TimeCheck = $CurDay} 163 | 164 | if ($TimeCheck -eq $CurDay){ 165 | $CurLine += "`"" + (Get-Date ($TimeMap.AddMinutes($Minutes)) -Format "MM/dd/yyyy HH:mm").tostring().substring(0,16)+"`",`"`",`"`"`n" 166 | } 167 | } 168 | 169 | $Minutes += $TweetInterval 170 | 171 | } else { 172 | if ($NewDay) {throw "-NewDay parameter must be used with -IncludeTime"} 173 | if ($IgnoreDayChange) {throw "-IgnoreDayChange parameter must be used with -IncludeTime"} 174 | if ($SetDate) {throw "-SetDate parameter must be used with -InlcudeTime"} 175 | 176 | $CurLine += "`"`",`"`",`"`"`n"} 177 | 178 | $Lines += $CurLine 179 | 180 | $Counter++ 181 | 182 | } until ($Counter -eq $Limit -or $CurDay -ne $TimeCheck) 183 | 184 | $NewLines = @() 185 | 186 | if ($SetDate) { 187 | 188 | if (!$NewDay) {throw "-SetDate must be used with -NewDay parameter"} 189 | 190 | ($Lines -split "`n") | % { 191 | #Write-Host $Lines 192 | if ($_.length -gt 2) { 193 | 194 | $DateLine = ($_ -split ",")[0] 195 | $MessageLine = ($_ -split ",")[1] 196 | $LinkLine = ($_ -split ",")[2] 197 | #Write-Host "who" 198 | Write-Debug "DateLine: $DateLine" 199 | Write-Debug "Date: $Date" 200 | Write-Debug "Message: $Message" 201 | Write-Debug "Link: $LinkLine" 202 | 203 | $Date=$DateLine.substring(1,10) 204 | $NewLines += (($DateLine -replace "$Date","$SetDate") + ",$MessageLine,$LinkLine") 205 | 206 | } 207 | } 208 | $Lines = $NewLines 209 | } 210 | #Write-Host $NewLines 211 | Out-File -FilePath $BulkPath -InputObject $Lines -Encoding utf8 -Force 212 | 213 | } 214 | -------------------------------------------------------------------------------- /Modules/RedditNinja/RedditNinja.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | Created by Mr.PowerScripts 3 | 4 | More Powershell examples at www.youtube.com/MrPowerScripts 5 | 6 | Become a Reddit ninja with this CMDLET 7 | You can easily browse reddit from within a powershell console 8 | 9 | 1.2 10 | Fixed a bug that caused an error when trying to lauch main reddits from a browser 11 | 12 | Version 1.1 13 | Added -Sub parameter to seach through subreddits 14 | 15 | Version 1.0 16 | 17 | -----------------INSTALLATION------------------------ 18 | 19 | If you have installed a previous version then use Remove-Module 20 | to remove the old version first 21 | 22 | 1. Create a folder called "RedditNinja" in your module folder and 23 | place RedditNinja.psm1 inside of it 24 | 25 | Type "$env:PSModulePath" in powershell to see different 26 | module paths on your local system 27 | 28 | C:\Users\USERNAME\Documents\WindowsPowerShell\Modules is one location you can 29 | place the RedditNinja folder 30 | 31 | If it doesn't exist you can create it. 32 | 33 | 2. Inside powershell type "Get-Module -ListAvailable" and you should now 34 | see Reddit Ninja as one of the options. 35 | 36 | 3. Type "Import-Module "RedditNinja" 37 | 38 | 4. Type "Get-Reddits" to see if the module was installed correctly 39 | 40 | 5. Enjoying being a Reddit Ninja 41 | 42 | -----------------USAGE----------------------- 43 | 44 | #Get-Reddits 45 | 46 | -will check if it has reddits stored, and if not will download 47 | the lastest 25 from reddit.com, and display them 48 | 49 | #Get-Reddits -new 50 | 51 | -forces Get-Reddits to download the lastest set of 25 from reddit.com 52 | 53 | #Get-Reddits -Index (integer set) 54 | 55 | -lets you show specific reddits from the stored index in three different ways 56 | a. Get-Reddits -Index 5 --- for a single record inside the index 57 | b. Get-Reddits -Index (1,5,13,25) --- will return only the index numbers specified 58 | c. Get_Reddits -Index (5..7) --- will return the items between 5 and 7. i.e (5,6,7) 59 | 60 | #Get-reddits -Browse (integer set) 61 | 62 | -Works the same way as -Index, except the values you provide here will launch those 63 | specific indexes into your default browser. 64 | 65 | #Get-Reddits -sub SubRedditName 66 | -downloads and displays subreddits from the specified subreddit 67 | 68 | -Note: the -new and -browse can be used with -Sub as well 69 | Get-Reddits -sub gaming -new 70 | Get-Reddits -sub Gaming -browse 1,5,6 71 | 72 | #> 73 | 74 | function Get-Reddits { 75 | <# 76 | .Description 77 | Run this cmdlet without any parameters to list all 25 articles on the reddit front page. 78 | Supply the browse parameter with a reddit to lauch it in the default browser 79 | #> 80 | 81 | Param ( 82 | 83 | [Parameter(Mandatory=$False,HelpMessage="Enter one or more values 1 or (1,4,15) or (3..7)")] 84 | [ValidateRange(1,25)] 85 | [array]$Index=(1..25), 86 | 87 | [Parameter(Mandatory=$False,HelpMessage="Enter a value between 1-25 to open this reddit page in a browser")] 88 | [ValidateRange(1,25)] 89 | [array]$Browse, 90 | 91 | [Parameter(Mandatory=$False,HelpMessage="Use this flag alone to download new reddits")] 92 | [switch]$New, 93 | 94 | [Parameter(Mandatory=$False,HelpMessage="Enter the name of a known subreddit to download the reddits")] 95 | [AllowEmptyString()] 96 | [string]$Sub 97 | ) 98 | cls 99 | 100 | if ($Sub.length -eq 0) { 101 | 102 | if ($New -eq $True -or $MainStorage -eq $Null) { 103 | 104 | Write-Host "Downloading new main threads" 105 | 106 | try { 107 | 108 | $WC = New-Object net.webclient 109 | $global:MainStorage = $WC.Downloadstring("http://www.reddit.com/.json") | ConvertFrom-json 110 | 111 | } catch { 112 | 113 | Write-Host "Error: Did you type the correct Subreddit? Is Reddit.com down?" 114 | break function 115 | } 116 | 117 | Write-Host "Threads Updated" 118 | 119 | break function 120 | } 121 | 122 | if ($browse.count -gt 0 -eq $true) { 123 | 124 | $Browse | ForEach-Object { 125 | $ix = $_-1 126 | 127 | $RedditURI= "http://www.reddit.com"+$MainStorage.data.children.Item(($ix)).data.permalink 128 | Invoke-Expression "start $RedditURI" 129 | 130 | } 131 | break function 132 | } 133 | 134 | [array]::Reverse($Index) 135 | 136 | $Index | ForEach-Object { 137 | 138 | $ix = $_-1 139 | 140 | "`n_ $_ ______________________________________________________" 141 | "title-------- "+$MainStorage.data.children.Item($ix).data.title 142 | "url---------- "+$MainStorage.data.children.Item($ix).data.url 143 | "PermaLink---- www.reddit.com"+$MainStorage.data.children.Item($ix).data.permalink 144 | "score-------- "+$MainStorage.data.children.Item($ix).data.score 145 | "ups---------- "+$MainStorage.data.children.Item($ix).data.ups 146 | "downs-------- "+$MainStorage.data.children.Item($ix).data.downs 147 | "author------- "+$MainStorage.data.children.Item($ix).data.author 148 | "Num_Comments- "+$MainStorage.data.children.Item($ix).data.num_comments 149 | } 150 | 151 | } elseif ($Sub.length -gt 0) { 152 | 153 | if ($new -eq $True -or $Sub -ne $SubReddit) { 154 | 155 | Write-Host "Downloading new sub threads" 156 | 157 | try { 158 | 159 | $WC = New-Object net.webclient 160 | $global:SubStorage = $WC.Downloadstring("http://www.reddit.com/r/$sub/.json") | ConvertFrom-json 161 | 162 | } catch { 163 | 164 | Write-Host "Error: Did you type the correct Subreddit? Is Reddit.com down?" 165 | 166 | break function 167 | } 168 | 169 | Write-Host "Threads Updated" 170 | 171 | } 172 | 173 | if ($browse.count -gt 0 -eq $true) { 174 | 175 | $Browse | ForEach-Object { 176 | $ix = $_-1 177 | $SubRedditURI= "http://www.reddit.com"+$SubStorage.data.children.Item(($ix)).data.permalink 178 | Invoke-Expression "start $SubRedditURI" 179 | } 180 | 181 | break function 182 | 183 | } 184 | 185 | $Global:Subreddit=$Sub 186 | 187 | [array]::Reverse($Index) 188 | 189 | $Index | ForEach-Object { 190 | 191 | $ix = $_-1 192 | 193 | "`n_ $_ ______________________________________________________" 194 | "title-------- "+$SubStorage.data.children.Item($ix).data.title 195 | "url---------- "+$SubStorage.data.children.Item($ix).data.url 196 | "PermaLink---- www.reddit.com"+$SubStorage.data.children.Item($ix).data.permalink 197 | "score-------- "+$SubStorage.data.children.Item($ix).data.score 198 | "ups---------- "+$SubStorage.data.children.Item($ix).data.ups 199 | "downs-------- "+$SubStorage.data.children.Item($ix).data.downs 200 | "author------- "+$SubStorage.data.children.Item($ix).data.author 201 | "Num_Comments- "+$SubStorage.data.children.Item($ix).data.num_comments 202 | 203 | } 204 | 205 | } 206 | }#End Else 207 | #End Get-Reddits 208 | -------------------------------------------------------------------------------- /Modules/TwitterNinja/TwitterNinja.psm1: -------------------------------------------------------------------------------- 1 |  2 | function Get-Tweets { 3 | 4 | <# 5 | 6 | Created by Mr.PowerScripts 7 | 8 | More Powershell examples at 9 | 10 | www.youtube.com/MrPowerScripts 11 | www.github.com/MrPowerScripts 12 | 13 | 14 | -----------------INSTALLATION------------------------ 15 | 16 | If you have installed a previous version then use Remove-Module 17 | to remove the old version first 18 | 19 | 1. Create a folder called "TwitterNinja" in your module folder and 20 | place TwitterNinja.psm1 inside of it 21 | 22 | Type "$env:PSModulePath" in powershell to see different 23 | module paths on your local system 24 | 25 | C:\Users\USERNAME\Documents\WindowsPowerShell\Modules is one location you can 26 | place the TwitterNinja folder 27 | 28 | If it doesn't exist you can create it. 29 | 30 | 2. Inside powershell type "Get-Module -ListAvailable" and you should now 31 | see Twitter Ninja as one of the options. 32 | 33 | 3. Type "Import-Module "TwitterNinja" 34 | 35 | 4. Type "Get-Reddits" to see if the module was installed correctly 36 | 37 | 5. Enjoying being a Twitter Ninja 38 | 39 | 40 | ------------ Usage --------------------------------- 41 | 42 | .DESCRIPTION 43 | This cmdlet will allow you to search twitter using any general search term - Such as Sports, WorldNews, TVShows - and displays the latest 15 tweets with that term. 44 | If you find tweets from a user and would like to see more tweets from them, you can provide their user name to see as many as their last 200 tweets. 45 | Finally, you can view their profile information, or launch their twitter page into your default browser from powershell. 46 | 47 | .PARAMETER 48 | -Search "SearchTerm" will search twitter for the provided term, and list the last 15 tweets 49 | 50 | -User "UserName" will display the last 20 tweets from that user 51 | 52 | -Index "Integer" can be used with -User to display up to 200 tweets. 53 | 54 | -Profile Can be used with -User to display information from that users twitter profile. 55 | 56 | -Browse Can be use with -User to launch their Twitter page in your local browser. 57 | 58 | .EXAMPLE 59 | 60 | Get-Tweets -Search Potato 61 | 62 | Get-Tweets -User MrPowerScripts 63 | 64 | Get-Tweets -User MrPowerScripts -Index 150 65 | 66 | Get-Tweets -User MrPowerScripts -Profile 67 | 68 | Get-Tweets -User MrPowerScripts -Browse 69 | 70 | #> 71 | 72 | Param ( 73 | 74 | [Parameter(Mandatory=$False,HelpMessage="Search the twitterverse by typing in a keyword")] 75 | [string]$Search, 76 | 77 | [Parameter(Mandatory=$False,HelpMessage="Enter a twitter name to see more info about their twitter page")] 78 | [string]$User, 79 | 80 | [Parameter(Mandatory=$False,HelpMessage="Array of integers to display")] 81 | [ValidateRange(1,200)] 82 | [array]$Index=(1..15), 83 | [switch]$New, 84 | [switch]$Profile, 85 | [switch]$Browse 86 | ) 87 | 88 | cls 89 | 90 | #Start of the search param 91 | if ($Search.length -gt 0) { 92 | 93 | if ($New -eq $True -or $TweetSearchStorage -eq $Null -or $Search.length -gt 0) { 94 | 95 | Write-Host "Updating info..." 96 | $WC = New-Object net.webclient 97 | try { 98 | $global:TweetSearchStorage = $WC.Downloadstring("http://search.twitter.com/search.json?q=$Search") | ConvertFrom-json 99 | } catch { 100 | 101 | Write-Host "Something went wrong. Maybe Twitter is down?" 102 | break function 103 | } 104 | } 105 | 106 | [array]::Reverse($Index) 107 | 108 | 109 | $Index | ForEach-Object { 110 | 111 | $ix=$_-1 112 | 113 | if (($TweetSearchStorage.results[$ix].created_at) -ne $Null) { 114 | 115 | [datetime]$CreateTime = $TweetSearchStorage.results[$ix].created_at 116 | 117 | Write-Host "___ $_ ____________________________________________" 118 | Write-Host ("Created----- "+$CreateTime.ToLocalTime()) 119 | Write-Host ("ScreenName-- "+$TweetSearchStorage.results[$ix].From_User) 120 | Write-Host ("Tweet------- "+$TweetSearchStorage.results[$ix].Text) 121 | Write-Host ("SentTo------ "+$TweetSearchStorage.results[$ix].To_User) 122 | Write-Host "`n" 123 | 124 | } 125 | 126 | } 127 | 128 | break function 129 | #End of search parameter 130 | } elseif ($user.length -gt 0) { 131 | #Start of the user param 132 | [int]$count = $Index[0] 133 | 134 | if ($count-eq1) {$Count=20} 135 | 136 | if ($New -eq $True -or $TweetUserStorage -eq $Null -or $user.length -gt 0) { 137 | 138 | Write-Host "Updating Info..." 139 | $WC = New-Object net.webclient 140 | try { 141 | $global:TweetUserStorage = $WC.Downloadstring("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=$user&count=$Count") | ConvertFrom-json 142 | } catch { 143 | 144 | Write-Host "Something went wrong. If you're searching tweets maybe twitter is down. If you're checking a user make sure you typed the name correctly" 145 | break function 146 | } 147 | } 148 | 149 | if ($Browse -eq $true) { 150 | 151 | $TwitterProfURI= "http://www.twitter.com/"+$user 152 | Invoke-Expression "start $TwitterProfURI" 153 | break function 154 | } 155 | 156 | if ($Profile -eq $true) { 157 | 158 | $Index = (1..$Count) 159 | 160 | [array]::Reverse($Index) 161 | 162 | $Index | ForEach-Object { 163 | 164 | $ix=$_-1 165 | 166 | if (($TweetUserStorage[$ix].user.screen_name) -ne "") { 167 | Write-Host "___________________________________________________" 168 | Write-Host ("ScreenName-- "+$TweetUserStorage[$ix].user.screen_name) 169 | Write-Host ("Name-------- "+$TweetUserStorage[$ix].user.name) 170 | Write-Host ("Location---- "+$TweetUserStorage[$ix].user.location) 171 | Write-Host ("Description- "+$TweetUserStorage[$ix].user.url) 172 | Write-Host ("Tweets------ "+$TweetUserStorage[$ix].user.statuses_count) 173 | Write-Host ("Protected--- "+$TweetUserStorage[$ix].user.protected) 174 | Write-Host ("Followers--- "+$TweetUserStorage[$ix].user.followers_count) 175 | Write-Host ("Following--- "+$TweetUserStorage[$ix].user.friends_count) 176 | Write-Host ("Favorites--- "+$TweetUserStorage[$ix].user.favourites_count) 177 | Write-Host ("TimeZone---- "+$TweetUserStorage[$ix].user.time_zone) 178 | Write-Host ("Language---- "+$TweetUserStorage[$ix].user.lang) 179 | 180 | Write-Host "`n" 181 | } 182 | break function 183 | } 184 | } 185 | 186 | $Index = (1..$Count) 187 | 188 | [array]::Reverse($Index) 189 | 190 | $Index | ForEach-Object { 191 | 192 | $ix=$_-1 193 | 194 | if ($TweetUserStorage[$ix].user.screen_name -ne $Null) { 195 | 196 | Write-Host "___ $_ ____________________________________________" 197 | Write-Host ("user------- "+$TweetUserStorage[$ix].user.screen_name) 198 | Write-Host ("Created---- "+$TweetUserStorage[$ix].created_at) 199 | Write-Host ("Source----- "+$TweetUserStorage[$ix].source) 200 | Write-Host ("text------- "+$TweetUserStorage[$ix].text) 201 | Write-Host ("RT Count--- "+$TweetUserStorage[$ix].Retweet_Count) 202 | Write-Host ("--------------------------------------------------") 203 | Write-Host ("Clear URL-- "+($TweetUserStorage[$ix].entities.urls | select -ExpandProperty display_url)) 204 | Write-Host ("HashTags--- "+($TweetUserStorage[$ix].entities.hashtags | select -ExpandProperty text)) 205 | Write-Host ("User Ment.- "+($TweetUserStorage[$ix].entities.usermentions | select -ExpandProperty screen_name)) 206 | 207 | Write-Host "`n" 208 | } 209 | 210 | } 211 | 212 | break function 213 | #End user parameter 214 | } else {Get-Help Get-Tweets} 215 | }#End Get-Tweet 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /Outlook/SendEmailFromOutlook.ps1: -------------------------------------------------------------------------------- 1 | $OL = New-Object -ComObject outlook.application 2 | 3 | Start-Sleep 5 4 | 5 | <# 6 | olAppointmentItem 7 | olContactItem 8 | olDistributionListItem 9 | olJournalItem 10 | olMailItem 11 | olNoteItem 12 | olPostItem 13 | olTaskItem 14 | #> 15 | 16 | #Create Item 17 | $mItem = $OL.CreateItem("olMailItem") 18 | 19 | $mItem.To = "PlayingWithPowershell@gmail.com" 20 | $mItem.Subject = "PowerMail" 21 | $mItem.Body = "SENT FROM POWERSHELL" 22 | 23 | $mItem.Send() 24 | 25 | -------------------------------------------------------------------------------- /Pipelining/PipeliningGetProcessColoredOutput.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | 3 | Get-Process | Foreach { 4 | 5 | if ($_.name -ilike "*chrome*") { Write-Host "$_" -ForegroundColor green} 6 | Elseif ($_.name -ilike "*powershell*") { Write-Host "$_" -ForegroundColor red} 7 | else {Write-Host "$_"} 8 | 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Pipelining/PipeliningVariables.ps1: -------------------------------------------------------------------------------- 1 |  2 | $Potato = "spud" 3 | 4 | #Write-Host -Object $Potato 5 | 6 | $Potato | Write-Host 7 | -------------------------------------------------------------------------------- /Printers/InstallDirectIPPrinter.ps1: -------------------------------------------------------------------------------- 1 | #This script shows different methods to installing a printer via Direct IP 2 | #And can be used to follow along while watching the associated video http://www.youtube.com/watch?v=E2x6NG72tn4 3 |  4 |  5 |  6 | switch ([system.environment]::OSVersion.Version.Major) { 7 | 8 | 5 {$PrnVBSDir = "$env:windir\system32"} 9 | 6 {$PrnVBSDir = "$env:windir\System32\Printing_Admin_Scripts\en-US\"} 10 | } 11 | 12 | ###################################################################### 13 | ###################### Deploy Driver ################################# 14 | ###################################################################### 15 | 16 | &C:\Users\Fern\Desktop\lj4200pcl5winxp2003vista2008-64.exe /auto C:\Users\Fern\Desktop\driver 17 | 18 | Write-Host "TOO FAST" -ForegroundColor Green 19 | 20 | 21 | Start-Process "C:\Users\Fern\Desktop\lj4200pcl5winxp2003vista2008-64.exe" -ArgumentList '/auto "C:\Users\Fern\Desktop\driver"' -Wait 22 | 23 | Write-Host "TOO FAST" -ForegroundColor Green 24 | 25 | #\\server\share\driver\hpc4200c.inf 26 | 27 | ################################################################################ 28 | ################# Installing the printer driver ################################ 29 | ################################################################################ 30 | 31 | &rundll32 printui.dll PrintUIEntry 32 | 33 | Start-Process "RunDll32" -ArgumentList 'printui.dll PrintUIEntry /ia /m "HP LaserJet 4200 PCL 5e" /h "x64" /v "Type 3 - User Mode" /f "C:\Users\Fern\Desktop\driver\hpc4200t.inf"' -Wait 34 | 35 | start-process "printui.exe" -ArgumentList '/ia /m "HP LaserJet 4200 PCL 5e" /h "x64" /v "Type 3 - User Mode" /f "C:\Users\Fern\Desktop\driver\hpc4200t.inf"' -Wait 36 | 37 | #--------------------------------------------------------------------------------- 38 | #----------------------- VBS METHOD --------------------------------------------- 39 | #--------------------------------------------------------------------------------- 40 | 41 | 42 | &cscript "$PrnVBSDir\prndrvr.vbs" -a -m "HP LaserJet 4200 PCL 5e" -v 3 -e "Windows x64" 43 | 44 | 45 | #--------------------------------------------------------------------------------- 46 | #----------------------Modify Printer Drivers ------------------------------------ 47 | #--------------------------------------------------------------------------------- 48 | 49 | $Driver = Get-WmiObject win32_printerdriver | where {$_.name -imatch "HP LaserJet 4200 PCL 5e"} 50 | 51 | $Driver.delete() 52 | 53 | ###################################################################### 54 | ################## Create the printer port ########################### 55 | ###################################################################### 56 | 57 | $Port = ([wmiclass]"win32_tcpipprinterport").createinstance() 58 | 59 | $Port.Name = "MyPrinterPort" 60 | $Port.HostAddress = "192.168.1.25" 61 | $Port.Protocol = "1" 62 | $Port.PortNumber = "9100" 63 | $Port.SNMPEnabled = $false 64 | $Port.Description = "Testing Create Port" 65 | 66 | $Port.Put() 67 | 68 | #--------------------------------------------------------------------------------- 69 | #--------------Modify Existing Ports---------------------------------------------- 70 | #--------------------------------------------------------------------------------- 71 | 72 | $Port = Get-WmiObject win32_tcpipprinterport | where {$_.name -ilike "MyPrinterPort"} 73 | 74 | $Port.Delete() 75 | 76 | $Port.Name = "MyPrinterPort2" 77 | $Port.HostAddress = "192.168.1.30" 78 | 79 | $Port.Put() 80 | 81 | #--------------------------------------------------------------------------------- 82 | #---------------------Create Port VBS Method-------------------------------------- 83 | #--------------------------------------------------------------------------------- 84 | 85 | &cscript "$PrnVBSDir\prnport.vbs" -a -md -r "MyPrinterPort4" -h "192.168.1.25" -o "raw" -n "9100" 86 | 87 | ###################################################################### 88 | ################# Installing The Printer ############################# 89 | ###################################################################### 90 | 91 | #--------------------------------------------------------------------------------- 92 | #------------------VBS Method----------------------------------------------------- 93 | #--------------------------------------------------------------------------------- 94 | 95 | &cscript "$PrnVBSDir\prnmngr.vbs" -a -p "PrinterName" -m "HP LaserJet 4200 PCL 5e" -r "MyPrinterPort2" 96 | 97 | #--------------------------------------------------------------------------------- 98 | #--------------------WMI Method-------------------------------------------- 99 | #--------------------------------------------------------------------------------- 100 | 101 | $Printer = ([wmiclass]"win32_Printer").createinstance() 102 | 103 | $Printer.Name = "MyWMIPrinter2" 104 | $Printer.DriverName = "HP LaserJet 4200 PCL 5e" 105 | $Printer.DeviceID = "MyWMIPrinter" 106 | $Printer.Shared = $false 107 | $Printer.PortName = "MyPrinterPort4" 108 | 109 | $Printer.Put() 110 | 111 | #--------------------------------------------------------------------------------- 112 | #-----------------Modify Existing Printer----------------------------------------- 113 | #--------------------------------------------------------------------------------- 114 | 115 | $Printer = Get-WmiObject win32_printer | where {$_.name -ilike "myWMIPrinter"} 116 | 117 | $Printer.PortName = "MyPrinterPort2" 118 | 119 | $Printer.put() 120 | 121 | $Printer.delete() 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PowerScripts 2 | ============ 3 | 4 | Powershell Scripts 5 | 6 | Need Help? Join me on Discord https://bit.ly/mrps-discord and checkout out https://mrpowerscripts.com for more content! 7 | 8 | These scripts do not come with a warranty, or guarantee. 9 | 10 | They may, or may not work for you. 11 | 12 | They may even cause a vortex that sucks you, your house, your dog and your city into some 13 | intra-dimensional reality. 14 | 15 | For the sake of yourself, and your loved ones: 16 | 17 | Always check the code before you run it on your own computer. 18 | 19 | 20 | Other than that - Enjoy the scripts! 21 | -------------------------------------------------------------------------------- /Reports/AdvancedHTMLReport.ps1: -------------------------------------------------------------------------------- 1 | #Generate our HTML Tables 2 | 3 | $Services = Get-Service | Select-Object DisplayName, Status | ConvertTo-Html -Fragment 4 | 5 | $Process = Get-Process | Select-Object Name, CPU | Sort-Object CPU -Descending | ConvertTo-Html -Fragment 6 | 7 | #Color the service column 8 | $Services = $Services | ForEach { 9 | 10 | $_ -replace "Running","Running" 11 | 12 | } 13 | 14 | $Services = $Services | ForEach { 15 | 16 | $_ -replace "Stopped","Stopped" 17 | 18 | } 19 | 20 | #Generate our full HTML with CSS styling 21 | $HTML = ConvertTo-Html -Body "$Services $Process" -Head "" 22 | 23 | #Output to a file 24 | $HTML | Out-File $FileLocation -------------------------------------------------------------------------------- /Reports/DynamicHTMLReport.ps1: -------------------------------------------------------------------------------- 1 | #Clear table body to run in over and over in ISE 2 | $TableBody,$StrBody="" 3 | 4 | #Grab the files to check and organize them by lastwritetime 5 | $Files = Get-ChildItem "$env:USERPROFILE\desktop\temp" | 6 | Select-Object name,@{name="Size(MB)";expression={ "{0:N0}" -f ($_.Length / 1mb) }} | 7 | Sort-Object 'name' 8 | 9 | #Generate custom colored tables based on the last write time of the file 10 | $Files | ForEach-Object { 11 | 12 | 13 | [int]$Var=$_.'size(mb)' 14 | 15 | if ($Var -gt 0) { 16 | 17 | if ($Var -gt 100) {$TableBody+="$($_.name)$($_.'size(mb)')"} 18 | elseif ($Var -gt 50) {$TableBody+="$($_.name)$($_.'size(mb)')"} 19 | elseif ($Var -gt 10) {$TableBody+="$($_.name)$($_.'size(mb)')"} 20 | elseif ($Var -gt 5) {$TableBody+="$($_.name)$($_.'size(mb)')"} 21 | else {$TableBody+="$($_.name)$($_.'size(mb)')"} 22 | } 23 | } 24 | 25 | 26 | #Place the table into pre-formatted HTML Table 27 | $Body =@" 28 | 29 | 30 | $TableBody 31 |
FilenameMB(s)
32 | "@ 33 | 34 | #Creat the CSS style for the entire report 35 | $Head = "" 36 | 37 | #Cram the body and the Head into completed HTML code 38 | $HTML = ConvertTo-Html -Body $Body -Head $Head 39 | 40 | #Create an HTML file in a temp directory 41 | $HTML | Out-File -filepath "C:\temp\test.html" -Force 42 | -------------------------------------------------------------------------------- /Reports/GetProcessWebReport.ps1: -------------------------------------------------------------------------------- 1 | $Name="Chrome" 2 | $Path=$env:USERPROFILE+"\desktop\HTMLTest.html" 3 | 4 | Get-Process | Where {$_.ProcessName -imatch "$Name"} | Select-Object Name, CPU | Sort-Object CPU -Descending | ConvertTo-Html -Head "" -Title "Processnames" | Out-File -FilePath $Path 5 | -------------------------------------------------------------------------------- /Strings/BasicQuotes&SpecialCharacters.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | #Special characters start with a ` and are interpreted within "" as well as $Variables 3 | Write-Host "`t This line starts with a tab" 4 | Write-Host '`t This line is interpreted literally' 5 | Write-Host "`r" 6 | Write-Host "-------------------------------" 7 | Write-Host "Before new line special character`nAfter new line character" 8 | Write-Host "`r" 9 | Write-Host 'Before new line special character`nNew line character is not interpreted' 10 | Write-Host "`r" 11 | Write-Host "-------------------------------" 12 | $Variable = "Powershell3" 13 | 14 | Write-Host "We're talking about $Variable" 15 | Write-Host "`r" 16 | Write-Host 'Were talking about $Variable' -------------------------------------------------------------------------------- /Strings/ReplaceStringInAFileorFiles.ps1: -------------------------------------------------------------------------------- 1 | #Change the string in one file 2 | $FileName = "C:\somefolder\somefile.txt" 3 | 4 | Get-Content "$FileName" | ForEach-Object { $_ -replace "@","O" } | Set-Content "C:\users\fern\Desktop\CleanGarden.txt" -Force 5 | 6 | 7 | #Change the string of multiple files 8 | Get-ChildItem "C:\somefolder\somesubfolder" | ForEach-Object { 9 | 10 | $Content = Get-Content $_.fullname 11 | 12 | $Content = ForEach-Object { $Content -replace "@","O" } 13 | 14 | Set-Content $_.fullname $Content -Force 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Tools/AdminLaunch.bat: -------------------------------------------------------------------------------- 1 | @ECHO off 2 | cls 3 | ECHO 1 - CMD 4 | ECHO 2 - PoSh 5 | ECHO 3 - PoSh ISE 6 | ECHO ------------------- 7 | set /p Choice=Select Environment?: 8 | 9 | IF %CHOICE% == 1 RunAs /user:SuperBeamer\MrPowerScripts %windir%\System32\cmd.exe 10 | IF %CHOICE% == 2 RunAs /user:SuperBeamer\MrPowerScripts %windir%\System32\WindowsPowerShell\v1.0\powershell.exe 11 | IF %CHOICE% == 3 RunAs /user:SuperBeamer\MrPowerScripts %windir%\System32\WindowsPowerShell\v1.0\powershell_ise.exe 12 | 13 | if %ERRORLEVEL% == 1 pause 14 | -------------------------------------------------------------------------------- /Tools/BasicRegistry.ps1: -------------------------------------------------------------------------------- 1 |  2 | #New-Item -Path "HKCU:\potato" 3 | 4 | #new-ItemProperty -Path "HKCU:\potato" -Name Spud -Value 12345 -PropertyType string 5 | 6 | #Set-ItemProperty -Path "HKCU:\potato" -Name Spud -Value 54321 7 | 8 | #new-ItemProperty -Path "HKCU:\potato" -Name Spuds -Value 67890 -PropertyType string 9 | 10 | #Get-Item -Path HKCU:\potato 11 | 12 | #Get-ItemProperty -Path HKCU:\potato -Name Spud | Select-Object spud 13 | 14 | #Remove-ItemProperty -Path HKCU:\potato -name spud 15 | 16 | #Remove-Item -Path HKCU:\potato -------------------------------------------------------------------------------- /Tools/ChoiceUI.ps1: -------------------------------------------------------------------------------- 1 | $title = "Penguins rule" 2 | 3 | $message = "Please select a option from this useless choice menu?" 4 | 5 | $10 = New-Object System.Management.Automation.Host.ChoiceDescription "&10","Display the number 10" 6 | $20 = New-Object System.Management.Automation.Host.ChoiceDescription "2&0","Display the number 20." 7 | $Ducks = New-Object System.Management.Automation.Host.ChoiceDescription "Du&cks","Ducks are evil" 8 | 9 | #--------------------------------------------------------------------------------------- 10 | 11 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($10, $20,$Ducks) 12 | 13 | #=================================================================================== 14 | 15 | $result = $host.ui.PromptForChoice($title, $message, $options, 0) 16 | 17 | 18 | 19 | #--------------------THE MAGIC---------------------------- 20 | 21 | switch ($result) 22 | { 23 | 0 {"10"} 24 | 1 {"20"} 25 | 2 {"Why would you choose ducks? They're evil!"} 26 | } -------------------------------------------------------------------------------- /Tools/CreateShortcut.ps1: -------------------------------------------------------------------------------- 1 |  2 | #Create a wscript.shell object 3 | $ComObj = New-Object -ComObject WScript.Shell 4 | 5 | #Use the createshortcut method and assign to a variable 6 | $ShortCut = $ComObj.CreateShortcut("$Env:USERPROFILE\desktop\My Shortcut.lnk") 7 | 8 | #Path to file shorcut will open 9 | $ShortCut.TargetPath = "$PSHOME\powershell.exe" 10 | 11 | #Describe the shortcut 12 | $ShortCut.Description = "This is my shortcut! Rawr!" 13 | 14 | #Returns the fullpatth you defined for the shortcut 15 | $ShortCut.FullName 16 | 17 | #How the window will behave when opened 18 | $ShortCut.WindowStyle = 7 19 | #1 - Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. 20 | #3 - Activates the window and displays it as a maximized window. 21 | #7 - Minimizes the window and activates the next top-level window. 22 | 23 | #Create a hotkey shortcut for your shortcut 24 | $ShortCut.Hotkey = "CTRL+SHIFT+F5" 25 | #Modifiers include - ALT+, CTRL+, SHIFT+, EXT+. 26 | #KeyName - a ... z, 0 ... 9, F1 .. F12 27 | 28 | #Provide an icon for your shortcut 29 | $ShortCut.IconLocation = "$Env:USERPROFILE\desktop\favicon.ico" 30 | #If left blank it will use the icon for the file you're calling 31 | 32 | $ShortCut.Save() 33 | 34 | 35 | #Create a wscript.shell object 36 | $ComObj = New-Object -ComObject WScript.Shell 37 | 38 | #Use the createshortcut method and assign to a variable 39 | $ShortCut = $ComObj.CreateShortcut("$Env:USERPROFILE\desktop\My Web Shortcut.url") 40 | 41 | #Path to URL 42 | $ShortCut.TargetPath = "http://www.youtube.com/mrpowerscripts" 43 | 44 | $ShortCut.Save() 45 | -------------------------------------------------------------------------------- /Tools/DiscoverUSBStorage.ps1: -------------------------------------------------------------------------------- 1 | Get-ChildItem "hklm:\SYSTEM\ControlSet001\Enum\USBSTOR" 2 | 3 | -------------------------------------------------------------------------------- /Tools/FindPathOfScriptFromScript.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | $LocalPath = ($MyInvocation.MyCommand.Path).tolower().replace("findpathofscriptfromscript.ps1","") -------------------------------------------------------------------------------- /Tools/Get-RemoteUserProfile.ps1: -------------------------------------------------------------------------------- 1 |  2 | function Get-RemoteProfile { 3 | 4 | param ( 5 | [parameter(mandatory=$true)] 6 | $Computer 7 | ) 8 | 9 | $Cred = Get-Credential 10 | 11 | Get-WmiObject -Class win32_userprofile -ComputerName $Computer -Credential $Cred | ft localpath, 12 | 13 | @{Name="LastUse";Expression={ 14 | [System.Management.ManagementDateTimeconverter]::ToDateTime($_.lastusetime) 15 | } 16 | } -AutoSize 17 | 18 | } -------------------------------------------------------------------------------- /Tools/HashFromFilesInFolderRecursive.ps1: -------------------------------------------------------------------------------- 1 | #Folders for input and output 2 | $ParentFolder = "C:\users\Fern\Desktop\scripts" 3 | $ExportFile = "C:\users\Fern\Desktop\supertest.txt" 4 | 5 | #Can use md5, sha1, and more depending on your .net version 6 | $Type="md5" 7 | 8 | #Looping through the files, generating hash, and appending to export file 9 | #the -file is exclusive to powershell 3 10 | $Files = Get-ChildItem $Parentfolder -Recurse -File 11 | 12 | #Create Empty Array To Store Hashes 13 | $Hashes=@() 14 | 15 | $Files | ForEach-Object { 16 | 17 | $fs = new-object System.IO.FileStream $_.fullname, "Open" 18 | $algo = [type]"System.Security.Cryptography.$Type" 19 | $crypto = $algo::Create() 20 | $hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "") 21 | $fs.Close() 22 | 23 | $Hashes += ($_.fullname.substring(3) + " $hash") 24 | 25 | } 26 | 27 | $Hashes | Out-File $ExportFile -Force -------------------------------------------------------------------------------- /Tools/IMGBurnEXESyntax.txt: -------------------------------------------------------------------------------- 1 | "C:\Program Files\ImgBurn\ImgBurn.exe" /start /bootemutype 0 /bootloadsegment 07C0 /bootsectorstoload 8 /bootimage \etfsboot.com /Mode build /rootfolder yes /outputmode imagefile /src /volumelabel /dest "".iso /FILESYSTEM "UDF" /NOIMAGEDETAILS /CLOSESUCCESS -------------------------------------------------------------------------------- /Tools/MountVHD.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | function VHD-Mount { 4 | Param ( 5 | [Parameter(Mandatory=$True)] 6 | [string]$Path 7 | ) 8 | 9 | if (Test-Path $Path) { 10 | 11 | $script = "SELECT VDISK FILE=`"$path`"`r`nATTACH VDISK" 12 | $script | diskpart 13 | 14 | } Else {Throw "VHD Could not be found"} 15 | 16 | } 17 | 18 | function VHD-UnMount { 19 | Param ( 20 | [Parameter(Mandatory=$True)] 21 | [string]$Path 22 | ) 23 | 24 | if (Test-Path $Path) { 25 | 26 | $script = "SELECT VDISK FILE=`"$path`"`r`nDETACH VDISK" 27 | $script | diskpart 28 | 29 | } Else {Throw "VHD Could not be found"} 30 | 31 | } -------------------------------------------------------------------------------- /Tools/PowershellStartUpParameters.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | Rem Run Powershell 4 | rem start /b powershell.exe -noexit -command "get-process" 5 | 6 | rem start /b powershell.exe -executionpolicy restricted 7 | 8 | rem start /b powershell.exe -file "C:\somefolder\somefile.ps1" 9 | 10 | rem start /b powershell.exe -NoLogo 11 | 12 | rem start /b powershell.exe -NoProfile 13 | 14 | rem start /b powershell.exe -sta 15 | 16 | rem start /b powershell.exe -version 2.0 17 | 18 | rem start /b powershell.exe -WindowStyle maximized 19 | rem Normal, Minimized, Hidden 20 | 21 | -------------------------------------------------------------------------------- /Tools/RestorePoints.ps1: -------------------------------------------------------------------------------- 1 | #Disable-ComputerRestore C: 2 | 3 | #Enable-ComputerRestore C: 4 | 5 | #Get-ComputerRestorePoint 6 | 7 | #Checkpoint-Computer -Description "Mr Powerscripts Test" -RestorePointType MODIFY_SETTINGS 8 | 9 | #Restore-Computer -RestorePoint 275 10 | -------------------------------------------------------------------------------- /Tools/ValidateIPAddress.ps1: -------------------------------------------------------------------------------- 1 |  2 | for (;;) { 3 | 4 | $IP = Read-Host -Prompt "Please enter a valid IP address" 5 | 6 | if ([bool]($IP -as [ipaddress])) {Write-Host "Thank you" -f Green;break} else {Write-Host "Invalid IP. You entered $IP" -f Red} 7 | 8 | } 9 | 10 | $IP -------------------------------------------------------------------------------- /Tools/WMI.ps1: -------------------------------------------------------------------------------- 1 | function show-games { 2 | 3 | $computer = "LocalHost" 4 | $namespace = "root\CIMV2\Applications\Games" 5 | $Game = Get-WmiObject -class Game -computername $computer -namespace $namespace 6 | 7 | $Game 8 | 9 | } 10 | 11 | function show-ratings { 12 | 13 | $computer = "LocalHost" 14 | $namespace = "root\CIMV2\Applications\WindowsParentalControls" 15 | $WPCRating = Get-WmiObject -class WpcRating -computername $computer -namespace $namespace 16 | 17 | $WPCRating.SyncRoot | Select-Object longname, description | Format-List 18 | } 19 | 20 | function show-bios { 21 | 22 | $computer = "LocalHost" 23 | $namespace = "root\CIMV2" 24 | $Bios = Get-WmiObject -class Win32_BIOS -computername $computer -namespace $namespace 25 | 26 | $bios 27 | 28 | } 29 | 30 | 31 | function show-keyboard { 32 | $computer = "LocalHost" 33 | $namespace = "root\CIMV2" 34 | $Keyboard = Get-WmiObject -class Win32_Keyboard -computername $computer -namespace $namespace 35 | 36 | $keyboard 37 | } -------------------------------------------------------------------------------- /Variables/CompareAgainstType.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | $Value = "4543",12 3 | 4 | 5 | if ($Value -is [int]) { 6 | Write-Host "$Value is a int" 7 | } 8 | 9 | if ($Value -is [string]) { 10 | Write-Host "$Value is a string" 11 | } 12 | 13 | 14 | if ($Value -is [array]) { 15 | Write-Host "$Value is a array" 16 | 17 | if ($Value[1] -is [int]) { 18 | Write-Host "The Second Value of the array is an int" 19 | } 20 | } -------------------------------------------------------------------------------- /Variables/EnvironmentVariables.ps1: -------------------------------------------------------------------------------- 1 | #Environment variables can be called upon from the reserved variable $env: 2 | $env:NUMBER_OF_PROCESSORS 3 | $env:HOMEPATH 4 | $env:COMPUTERNAME 5 | $env:OS 6 | 7 | 8 | #Variables in Powershell are evaluated first when inside " " 9 | Write-Host "$env:HOMEPATH\desktop" 10 | 11 | #Displays all environment variables 12 | Get-ChildItem env: 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Variables/ExitCode.ps1: -------------------------------------------------------------------------------- 1 |  2 | Invoke-Expression -Command "C:\users\fern\exitCode.ps1" 3 | cls 4 | if ($LastExitCode -eq "12") {Write-Host "ErrorCodeCaught!"} -------------------------------------------------------------------------------- /Variables/ReservedVariables.ps1: -------------------------------------------------------------------------------- 1 | $True 2 | 3 | $False 4 | 5 | $? 6 | 7 | Get-Process 8 | 9 | If ($? -eq $True) {Write-Host "Output"} 10 | 11 | -------------------------------------------------------------------------------- /Variables/VariablesInPowershell.ps1: -------------------------------------------------------------------------------- 1 |  2 | #Variables start with a $ in Powershell 3 | 4 | #These are valid variables 5 | $Variable 6 | $ThisIsAVariableToo 7 | $ThisIsAlsoAVariable 8 | 9 | #You can also set variables like this 10 | Set-Variable -Name Variablename -Value VariableValue 11 | 12 | #Or like this - you don't need to declare types in powershell 13 | $Variable = 3 14 | $ThisIsAVariableToo = "it's true" 15 | $ThisIsAlsoAVariable = $True 16 | 17 | #Or even like this 18 | [String]$Season = "Winter" 19 | [int]$Month = "1" 20 | [bool]$TrueFalse = $False 21 | [array]$Things = ("1thing","2thing","3thing") 22 | 23 | cls #Clears the host 24 | 25 | #Write the values of our assigned variables to the host 26 | Write-Host $Variable 27 | Write-Host $ThisIsAVariableToo 28 | Write-Host $ThisIsAlsoAVariable 29 | Write-Host $Season 30 | Write-Host $Month 31 | Write-Host $TrueFalse 32 | Write-Host $Things 33 | 34 | 35 | --------------------------------------------------------------------------------