r/usefulscripts • • May 24 '16

[AUTOHOTKEY] Win+X menu recreated in AutoHotKey, for WinXP and newer

36 Upvotes

http://pastebin.com/ddNA9Vzm This is a condensed version of a tool I made to help with mundane computer repair tasks. I got frustrated that the ever-helpful Win+X menu was only available on Win8 and newer, so I made my own. Compile it using the compiler that ships with AutoHotKey and you've got a standalone, portable Win+X menu that works on all systems XP and newer. No libraries needed, no frameworks, no admin privileges either! If it needs elevation, it will request it like any other program. Works on 32-bit and 64-bit OS.

Preview


r/usefulscripts • • Jan 04 '16

A script to terminate employees in office 365

Thumbnail
github.com
36 Upvotes

r/usefulscripts • • Apr 14 '23

If you post a link to the O365 blog spam site you will be immediately permanently banned

35 Upvotes

Linking to blog spam is expressly prohibited in sub rules.

Edit: banned domains are o365reports.com and m365scripts.com


r/usefulscripts • • Aug 08 '15

[POWERSHELL] IISLogsCleanup.ps1 is a script to compress and archive IIS logs (or any folder full of files really)

Thumbnail
exchangeserverpro.com
35 Upvotes

r/usefulscripts • • Aug 21 '22

[PowerShell] PSTeams - Adaptive Cards with Tables and Linebreaks in Microsoft Teams

34 Upvotes

If you are using Microsoft Teams, one of the available features is Incoming Webhooks. It allows you to send messages to the Microsoft Teams channel, which is very useful for many tasks. PSTeams, a module that I wrote, simplifies this process as you usually would be playing with JSON a lot. With the additions of Adaptive Cards, JSON became even harder to manage, as the features available make it worthwhile with lots of features but at the same time prone to errors.

So PSTeams does the work for you. Till today to create a table with data sent to teams, you would have to play a lot with Adaptive Column, ColumnSet, and Textboxes. These new features automate it.

Blog post describing new features and usage: https://evotec.xyz/adaptive-cards-with-tables-and-linebreaks-in-microsoft-teams/

What you get with the new 2.2 versions is New-AdaptiveTable and New-AdaptiveLineBreak. So with just one line of code, you can send Get-Drive, Get-Process or whatever without manual intervention.

Sources: https://github.com/EvotecIT/PSTeams

Here's an example of an Adaptive Card sent to Microsoft Teams from PowerShell

$URL = "incoming webhook"

# Lets create a new adaptive card
$Card = New-AdaptiveCard {
    # lets add some text, table and line breaks
    New-AdaptiveTextBlock -Size 'Medium' -Weight Bolder -Text 'Table usage with PSCustomObject 🔥' -Wrap
    New-AdaptiveTable -DataTable $Objects
    New-AdaptiveLineBreak
    New-AdaptiveTextBlock -Size 'Medium' -Weight Bolder -Text 'Table usage with OrderedDictionary 🤷‍♂️' -Wrap
    New-AdaptiveTable -DataTable $ObjectsHashes
    New-AdaptiveLineBreak
    New-AdaptiveTextBlock -Size 'Medium' -Weight Bolder -Text 'Table usage with display as PSCustomObject ❤️' -Wrap
    New-AdaptiveTable -DataTable $ObjectsHashes -DictionaryAsCustomObject -HeaderColor Attention
    New-AdaptiveTextBlock -Text 'Different example' -Size Large -Subtle -Spacing ExtraLarge
    New-AdaptiveLineBreak
    # and here we mix it with some sample from Adaptive cards
    New-AdaptiveContainer {
        New-AdaptiveColumnSet {
            New-AdaptiveColumn {
                New-AdaptiveImage -Url "https://adaptivecards.io/content/cats/3.png" -Size Medium -AlternateText "Shades cat team emblem" -HorizontalAlignment Center
                New-AdaptiveTextBlock -Weight Bolder -Text 'SHADES' -HorizontalAlignment Center
            } -Width Auto
            New-AdaptiveColumn {
                New-AdaptiveTextBlock -Text "Sat, Aug 31, 2019" -HorizontalAlignment Center -Wrap
                New-AdaptiveTextBlock -Text "Final" -Spacing None -HorizontalAlignment Center
                New-AdaptiveTextBlock -Text "45 - 7" -HorizontalAlignment Center -Size ExtraLarge
            } -Width Stretch -Separator -Spacing Medium
            New-AdaptiveColumn {
                New-AdaptiveImage -Url "https://adaptivecards.io/content/cats/2.png" -Size Medium -HorizontalAlignment Center -AlternateText "Skins cat team emblem"
                New-AdaptiveTextBlock -Weight Bolder -Text 'SKINS' -HorizontalAlignment Center
            } -Width Auto -Separator -Spacing Medium
        }
    }
    # and lets convert Get-Process into Adaptive card
    New-AdaptiveTextBlock -Text 'Lets convert Get-Process into Adaptive Table' -Size Large -Subtle -Spacing ExtraLarge
    New-AdaptiveLineBreak
    $TableData = Get-Process | Select-Object -First 5 -Property Name, Id, CompanyName, CPU, FileName
    New-AdaptiveTable -DataTable $TableData -HeaderHorizontalAlignment Center -HorizontalAlignment Center -HeaderColor Good -Size Small
} -Uri $URL -FullWidth -ReturnJson
$Card | ConvertFrom-Json | ConvertTo-Json -Depth 20

Enjoy! :-)


r/usefulscripts • • Feb 05 '21

[C++] Power Up Your Barcode Scanner With Scripts

34 Upvotes

https://github.com/oschwartz10612/Scanner-Pro-MK3

I worked for a school IT department that had 1000s of computers to manage each with a unique barcode. When imaging every year we had to go through and type in the barcode manually to each PXI screen and fill out some other info.

So I designed a little Arduino based board that would sit in between barcode scanners and the computer so all we had to do was plug it in as we went down the line of machines and scan the code. It would append the necessary info to the ID and fill out the rest of the form. We ended up using it for all of the machines and other barcode based management forms we had to do throughout the year.

I wrote a simple little library that allows for the creation of scripts in C using Arduino (its easier than you think if you have not done it before). There are also some scripts already on the Github if they sound useful!

I am thinking about doing a limited run of boards to sell on Tindie so you dont have to do the soldering and ordering. Would come with the board and a 3D printed case. If you are interested, you can add your email here and I will send more info.


r/usefulscripts • • Sep 21 '20

[TERRAFORM] Cloud/Browser-based Workstation

Thumbnail
github.com
34 Upvotes

r/usefulscripts • • Jun 13 '19

[PowerShell] Script to automatically upload file(s) via FTP to destination.

34 Upvotes

So I created this script to upload any files I have on my local machine in a specific directory and upload it to my Plex server. This script keeps the same folder structure that the files are in originally and logs all relevant info. It also checks if a file is already on the FTP and removes it locally if it already exists. I could definitely use some advice one how to make it better. Right now, its very rudimentary and could use some help make it better!

GitHub


r/usefulscripts • • Aug 27 '18

[PowerShell] How to get remote system information - Part 4

Thumbnail
sconstantinou.com
34 Upvotes

r/usefulscripts • • Nov 19 '17

[PowerShell] Change Bulk Users Home Drive Path in Active Directory

Thumbnail
bwya77.com
34 Upvotes

r/usefulscripts • • Jan 23 '17

[POWERSHELL] Using Jenkins to deploy an AWS instance, and update the DNS in cloudflare

34 Upvotes

I have created a Jenkins template with powershell scripts to launch an EC2 instance in AWS, add an elastic IP, and then create or update cloudflare DNS for the new instance.

The template for jenkins and the scripts can be found in my github here

If your interested in a better explanation whats going on I'm doing a series of how the whole thing works here on my blog


r/usefulscripts • • Oct 28 '15

[CSV File] FCC Telemarketer and RoboCall Blacklist for Google Contacts (10/26/2015)

Thumbnail
pastebin.com
34 Upvotes

r/usefulscripts • • Jul 03 '15

[POWERSHELL] Get-ADInfo.ps1 - PowerShell to collect details about Active Directory (such as FSMO role holders)

Thumbnail
paulcunningham.me
34 Upvotes

r/usefulscripts • • Mar 30 '15

[BASH] Shows detailed info on network interfaces and hard drives in a nice ASCII table

Thumbnail
github.com
34 Upvotes

r/usefulscripts • • Nov 05 '24

[POWERSHELL] Script to scan all OST files on computer and repair them.

33 Upvotes
# Function to find Outlook OST files modified in the past week
function Get-OutlookOstFiles {
    $outlook = New-Object -ComObject Outlook.Application
    $namespace = $outlook.GetNamespace("MAPI")
    $oneWeekAgo = (Get-Date).AddDays(-7)
    $ostFiles = @()
    foreach ($store in $namespace.Stores) {
        if ($store.ExchangeStoreType -eq 1 -or $store.ExchangeStoreType -eq 2) {
            $filePath = $store.FilePath
            if ($filePath -match "\.ost$" -and (Get-Item $filePath).LastWriteTime -ge $oneWeekAgo) {
                $ostFiles += $filePath
            }
        }
    }
    $ostFiles
}

# Close Outlook if running, wait for 10 seconds to see if it closes on its own
$process = Get-Process outlook -ErrorAction SilentlyContinue
if ($process) {
    $process.CloseMainWindow()
    Start-Sleep -Seconds 10
    $process.Refresh()
    if (!$process.HasExited) {
        $process | Stop-Process -Force
    }
}

# Determine if Outlook is 64-bit or 32-bit and set the scanpst path accordingly
$officeBitness = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" -Name "Platform"
$programFilesPath = if ($officeBitness -eq "x64") {
    "$env:ProgramFiles"
} else {
    "$env:ProgramFiles (x86)"
}
$scanpstPath = "$programFilesPath\Microsoft Office\root\Office16\SCANPST.EXE"

# Define the path to the Outlook profile directories in AppData\Local
$profilePath = "$env:LOCALAPPDATA\Microsoft\Outlook"

# Get all OST files modified in the past week in the profile directories
$ostFiles = Get-ChildItem -Path $profilePath -Filter "*.ost" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -ge (Get-Date).AddDays(-7) }

# Scan and repair each OST file
if ($ostFiles) {
    foreach ($ostFile in $ostFiles) {
        $fullPath = $ostFile.FullName

        # Run scanpst on the OST file
        $command = "& `"$scanpstPath`" -file `"$fullPath`" -force -rescan 10"
        Write-Host "Running command: $command"
        $process = Start-Process -FilePath $scanpstPath -ArgumentList "-file `"$fullPath`" -force -rescan 10" -NoNewWindow -Wait -PassThru
        $process.WaitForExit()

        # Determine the log file path
        $logFile = [System.IO.Path]::ChangeExtension($fullPath, ".log")

        # Open the log file in Notepad
        if (Test-Path $logFile) {
            Start-Process "notepad.exe" -ArgumentList $logFile
        } else {
            Write-Host "Log file not found: $logFile"
        }
    }
    Write-Host "OST files have been scanned and repaired."
} else {
    Write-Host "No OST files found."
}

# Wait 5 seconds before launching Outlook
Start-Sleep -Seconds 5

# Launch Outlook using the full path as the current user
$outlookPath = "$programFilesPath\Microsoft Office\root\Office16\OUTLOOK.EXE"
Start-Process -FilePath $outlookPath -NoNewWindow

r/usefulscripts • • Dec 19 '18

[Request] PowerShell script that restarts servers, checks for a successful ping and then if ANY do not reply back, perform action A. If ALL reply back, perform go to next set of servers.

33 Upvotes

So lets say that I want to restart servers A-C. Then I want to run a loop statement that pings each one until ALL of them give a response. If ANY of them fail to give a reply, I want to keep pinging them until they come online. Then once ALL of them have given a reply, to move to servers D-F and run the same commands on them. Then finally go to the last set of servers, G-I.


r/usefulscripts • • Jul 21 '17

[PowerShell] Get new desktop background pictures from reddit

33 Upvotes

Here's a script I wrote I've been using for a while now. I have it running once a day as a scheduled task. It will download new images from the /r/WQHD_Wallpaper subreddit to a folder you specify, which for me is the folder Windows uses to display background images on my desktop.

https://pastebin.com/UpTRQk8A

Tested and working on PS v5; untested but may work on earlier versions. Enjoy! :)


r/usefulscripts • • Aug 26 '16

[BASH] If you ever wanted to quickly create 10 SFTP servers with their /mnt directory mounted on the host

33 Upvotes

Title is kind of sarcastic because I am sure not many of you would need anything like this... But I did (for about 2 hours while testing a software feature).

Thought I would share it here in case useful at all.

It depends on Docker and a Docker image luzifer/sftp-share (if you are to run this script, I would recommend you learn what is in this image first).

Before running anything, make sure you know what this script is doing. I did this very quickly so there are a lot of hard coded values. Directories in ~/Downloads/ are affected and ports 2001 to 2010 are bound.

Once run, you can access the sftp servers by <host-ip>:<bound-port> from anywhere within the internal network. If you want to access them via the host, you could use <container-ip>:22.

create_10_ftp_servers_quickly

#!/bin/bash

# Depends on Environment Variable ${FTP_USER} and ${FTP_PASS} to be defined
# before running this script, if so comment out the following 2 lines
FTP_USER=default_user
FTP_PASS=default_pass

for FTP_NO in `seq 1 10`;
    do
        mkdir -p ~/Downloads/ftp_servers/ftp${FTP_NO}/
        cd ~/Downloads/ftp_servers/ftp${FTP_NO}/
        echo Provisioning FTP server ${FTP_NO}

        sudo docker run -it -d \
            -e USER=${FTP_USER} \
            -e PASS=${FTP_PASS} \
            -p $((2000+FTP_NO)):22 \
            -v /home/dean/Downloads/ftp_servers/ftp${FTP_NO}/:/mnt \
            --name=ftp${FTP_NO} \
            luzifer/sftp-share

        ftp_pid=`sudo docker inspect --format '{{ .State.Pid }}' ftp${FTP_NO}`
        ftp_ip=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' ftp${FTP_NO}`
        echo Provisioned FTP server with docker container id: ${ftp_pid} \
             and IP Address: ${ftp_ip}
        sudo docker inspect ftp${FTP_NO} > ftp${FTP_NO}_details.txt
    done

delete_10_ftp_servers_quickly

#!/bin/bash

for FTP_NO in `seq 1 10`;
    do
        echo Stopping FTP Server:
        sudo docker stop ftp${FTP_NO}
        echo Deleting FTP Server:
        sudo docker rm ftp${FTP_NO}
        echo Cleaning up FTP artifacts
        rm -rf ~/Downloads/ftp_servers/ftp${FTP_NO}/
    done

r/usefulscripts • • Aug 25 '16

[BASH] Block All China IP's with IPTables

Thumbnail
pastebin.com
33 Upvotes

r/usefulscripts • • Apr 21 '16

[Powershell] GPO set google as default search provider

33 Upvotes

Hey,

Cooked together this script to set google as default for IE

The say you can do the settings directly in the GPO, but I like this way better

I have a batch file to call on the .ps1 so I don’t have to set the pwoershell execution policy on each system

Anyways, here it is

Batch file:


Powershell.exe -ExecutionPolicy Bypass -File "\domain.com\login\set google as search engine IE.ps1"


Powershell script:


$user = [Environment]::UserName

<#the whole if statement is a failsafe so that it doesn't set google as searchprovder EVERY time you log in#>

if (( test-path "c:\users$user\AppData\LocalLow\Microsoft\Internet Explorer\Services\google_gpo.ico") -like "False") {

"running script"

<#create custom reg value so it doesn't break anything on system#>

$regvalue = "{"+[Guid]::NewGuid().ToString().ToUpper()+"}"

$regvalue

$user = [Environment]::UserName

<#copy the icon from c:\users$user\AppData\LocalLow\Microsoft\Internet Explorer\Services\ beforehand and put into DFS share from a system that has Google as search provider#>

copy "\domain.com\Login\google_gpo.ico" "c:\users$user\AppData\LocalLow\Microsoft\Internet Explorer\Services\google_gpo.ico"

New-Item -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes" -Name $regvalue –Force

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes" -Name DefaultScope -Value $regvalue

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name DisplayName -Value Google -PropertyType String

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name FaviconPath -Value "c:\users$user\AppData\LocalLow\Microsoft\Internet Explorer\Services\google_gpo.ico" -PropertyType String

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name FaviconURL -Value https://www.google.com/favicon.ico -PropertyType String

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name OSDFileURL -Value https://www.microsoft.com/en-us/IEGallery/GoogleAddOns -PropertyType String

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name ShowSearchSuggestions -Value 1 -PropertyType DWord

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name SuggestionsURL -Value "https://www.google.com/complete/search?q={searchTerms}&client=ie8&mw={ie:maxWidth}&sh={ie:sectionHeight}&rh={ie:rowHeight}&inputencoding={inputEncoding}&outputencoding={outputEncoding}" -PropertyType String

New-ItemProperty -Path "HKCU:\Software\Microsoft\Internet Explorer\SearchScopes$regvalue" -Name URL -Value "https://www.google.com/search?q={searchTerms}&sourceid=ie7&rls=com.microsoft:{language}:{referrer:source}&ie={inputEncoding?}&oe={outputEncoding?}" -PropertyType String

copy \ennsbros.com\Login\google_gpo.ico "c:\users$user\AppData\LocalLow\Microsoft\Internet Explorer\Services\google_gpo.ico"

}

else

{

"google already set as search engine"

}


Cheers


r/usefulscripts • • Feb 10 '15

[POWERSHELL] Test-ExchangeServerHealth.ps1 - Generate a health report for an Exchange Server 2010/2013 environment

Thumbnail
exchangeserverpro.com
33 Upvotes

r/usefulscripts • • Dec 21 '14

200+ GPL'd: bash scripts;perl scripts; bash functions (updates today)

Thumbnail trodman.com
33 Upvotes

r/usefulscripts • • Oct 20 '14

[BASH] Run a command whenever something in a directory (or its subs) has been saved

33 Upvotes
inotifywait -r path/to/dir -m -e close_write | while read file; do cmd1; cmd2; cmd3; done

r/usefulscripts • • Dec 27 '13

[PowerShell] Output Dell Warranty Information

Thumbnail
pastebin.com
33 Upvotes