r/usefulscripts • • Jun 13 '23

PowerShell HTML based Live Ping Monitor Demo

Thumbnail
vcloud-lab.com
39 Upvotes

r/usefulscripts • • Apr 16 '23

[PowerShell] Track Ubiquiti Unifi Stock and get notified of changes

39 Upvotes

I wrote this little PowerShell module that tracks Ubiquiti Stock in their stores worldwide and allows you to wait for a specific product and get a notification about it. Once it hits what you've waited for, it will open up a webpage to the product you want and make speech synthesis Hey, there is stock available for XXX.

It's as simple as that, but also very functional. It allowed me to buy equipment that I couldn't get ahold of because it was never in stock.

Here are a couple of examples (pick one):

Wait-UnifiStock -ProductName 'Access Point AC Lite' -Seconds 60
Wait-UnifiStock -ProductSKU 'UDR-EU' -ProductName 'Switch Flex XG' -Seconds 60
Wait-UnifiStock -ProductName 'UniFi6 Mesh', 'G4 Doorbell Pro', 'Camera G4 Pro', 'Test' -Seconds 60

I wrote a blog post about it (how to use it, with some screenshots)

Sources are available at GitHub:

I used this tool to open PowerShell when I started my work, use the Wait-UnifiStock command, and shut it down when going to lunch or finishing my work.

The module supports multiple countries, such as the USA, Europe, and others.

Just so you know - using anything below 60 seconds of refresh time, while possible, may get you banned. I don't know the exact number when anti-spam thresholds kick in, but we want to keep the Ubiquiti shop fast and smooth.

I hope this helps someone like it helped me. Enjoy


r/usefulscripts • • Oct 26 '22

[PowerShell] Using PowerShell for KMS activation, instead of slmgr.vbs

39 Upvotes

It's a drop-in replacement for slmgr.vbs script. Today I stumbled upon the script I created and shared here 2 years ago. I checked that and made some improvements.

The differences from slmgr.vbs:

  • You can provide an array of computer names, and it is up to you how you get them. It's just PowerShell.

  • It works on PowerShell version 5.0 and above. It means PowerShell 7.0 is ok, too.

  • It uses WinRM for remote computers. Check if remote computers are accessible over WinRM.

  • It includes a list of KMS keys, so that you don't have to for most of them. It covers some of the versions, not all of them.

  • It works even if you disabled cscript and wscript.

  • The code is documented and readable, so that you can improve according to your needs.

Gist:

It's a drop-in replacement for slmgr.vbs script (github.com)


r/usefulscripts • • Mar 24 '21

Script sharing: Monitoring and auditing external file accesses in Microsoft 365

39 Upvotes

The external sharing feature lets users in your organization share content with people outside the organization (such as partners, vendors, clients, or customers). So, it's necessary to audit who accessed the file to ensure each user is authorized.

To track external users' file access, Microsoft doesn't provide any built-in report. So, I have created a PowerShell script that helps to find who accessed which file and when.

You can download the script from Github.


r/usefulscripts • • Dec 18 '17

Microsoft Powershell generate random anything (Filename, TempPath, GUID)

Thumbnail
vcloud-lab.com
39 Upvotes

r/usefulscripts • • Nov 08 '17

Find and Remove unnecessary licenses on shared mailboxes in all customer Office 365 tenants

39 Upvotes

Here's our PowerShell script for finding and removing unnecessary licenses on shared mailboxes in all customers' Office 365 tenants.

Prior to using an offboarding script, we used to manually convert users to shared mailboxes, and then remove the Office 365 licenses. If we forgot to remove the license, the customer/us would continue getting billed for it.

This script will search all customer tenants for shared mailboxes with a license, and then give you the option to remove the licenses from each one.

Once you've run this, you may also want to run this script to check all tenants for unused Office 365 licenses

In our case, we've set up an Azure Function and a Microsoft Flow to send us email alerts when unused licenses are detected. See the guide to set this up here..


r/usefulscripts • • Oct 17 '17

Powershell: Temporary group membership on Windows 2016 Active Directory

Thumbnail
vcloud-lab.com
39 Upvotes

r/usefulscripts • • Sep 04 '15

[Powershell] RDP into a lot of servers, set my default desktop settings in one shot

39 Upvotes

As a consultant I login to so many servers I can't even. I can't stand the default settings (hide file extensions? WTF were they thinking? On a server even! Grrr) Plus fucking IE, don't get me started. So the second I login to a new server I immediately open Powershell as Administrator an paste this script in, my life has improved by several orders of magnitude.

http://pastebin.com/7kRN3V3J


r/usefulscripts • • Jan 26 '15

Get folder sizes using Robocopy(!) and PowerShell. Blazingly fast.

Thumbnail
powershelladmin.com
39 Upvotes

r/usefulscripts • • Nov 12 '14

[BATCH] Remotely create a keyboard shortcut to trigger a BSOD

39 Upvotes

This is useful for debugging, or any other time you might need a user to be able to create a crash dump. Needs windows 7 for timeout function, and admin rights. I don't remember where I got the resolve service state from, but I'm pretty sure it's part of someone else's script

    @echo off
cls
echo You need to have local admin rights on the remote machine for this to work.
echo.
echo.
echo What's the name of the Computer you want to add a crash keyboard shortcut to?
set /p _compName=""
ping -n 1 %_compName% | FIND "TTL=" >NUL
IF errorlevel 1 GOTO SystemOffline
SC \\%_compName% query RemoteRegistry | FIND "STATE" >NUL
IF errorlevel 1 GOTO SystemOffline

:ResolveInitialState
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO running
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "STOPPED" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StopedService
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "PAUSED" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO SystemOffline
cls
echo Service State is changing, waiting for service to resolve its state before making changes
sc \\%_compName% query RemoteRegistry | Find "STATE"
timeout /t 2 /nobreak >NUL
GOTO ResolveInitialState

:StopedService
Echo RemoteRegistry is stopped
goto start

:start
ECHO Starting Remote Registry.
SC \\%_compName% start RemoteRegistry

:starting
echo Starting RemoteRegistry on %_compName%
timeout /t 2 /nobreak>nul
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StartedService
goto starting

:StartedService
echo Service RemoteRegistry is started on %_compName%.
echo.
goto running 

:running
cls
Echo RemoteRegistry is running
echo.
echo Adding reg key
reg add \\%_compName%\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\kbdhid\Parameters /v CrashOnCtrlScroll /t REG_DWORD /d 00000001 /f
pause>nul
ECHO Done. Press Right Ctrl key and Scroll lock twice to generate BSOD.
exit

:SystemOffline
cls
ECHO System is offline.
pause>nul
exit

r/usefulscripts • • Apr 06 '19

[PowerShell] Out-HtmlView – HTML alternative to Out-GridView - Cross-Platform

Thumbnail
evotec.xyz
38 Upvotes

r/usefulscripts • • Mar 31 '19

[PowerShell] Backing up Bitlocker Keys and LAPS passwords from Active Directory

Thumbnail
evotec.xyz
38 Upvotes

r/usefulscripts • • Mar 06 '19

[PowerShell] Meet Statusimo - PowerShell generated Status Page

Thumbnail
evotec.xyz
38 Upvotes

r/usefulscripts • • Sep 17 '15

[BATCH] Tron v6.6.1 (2015-09-14) // Expand Win7/8/8.1 telemetry purge; Add supporting code for upcoming Windows 10 telemetry purge; update subtools

38 Upvotes

NOTE: Tron now has it's own subreddit. Check it out at /r/TronScript


Background

Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually and decided to just script the whole thing. I hope this helps other techs and admins.


Stages of Tron:

0. Prep: caffeine, rkill, ProcessKiller, TDSSKiller, Stinger, registry backup, WMI repair, sysrestore clean, oldest VSS set purge, create pre-run System Restore point

  1. Tempclean: TempFileCleanup, CCLeaner, BleachBit, backup & clear event logs, Windows Update cache cleanup, Internet Explorer cleanup, USB device cleanup

  2. De-bloat: remove OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\; Metro OEM debloat (Win8/8.1/2012 only)

  3. Disinfect: Kaspersky VRT, Sophos AV, Malwarebytes Anti-Malware, DISM image check (Win8/2012 only)

  4. Repair: Registry permissions reset, Filesystem permissions reset, SFC /scannow, chkdsk (if necessary), remove Windows "telemetry" (user tracking)

  5. Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some PDQ packs); then installs any pending Windows updates

  6. Optimize: page file reset, defrag %SystemDrive% (usually C:; skipped if SSD is detected)

  7. Wrap-up: Send job completion email report (if configured; specify SMTP settings in \resources\stage_7_wrap-up\email_report\SwithMailSettings.xml

  8. Manual stuff: Additional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)

Saves a log to C:\Logs\tron.log (configurable).


Screenshots

Welcome Screen | Email Report | New version detected | Help screen | Config dump | Dry run | Pre-run System Restore checkpoint | Disclaimer


Changelog

(full changelog on Github)

v6.6.1 (2015-09-14)

  • * stage_4_repair:telemetry: Expand telemetry purge actions (Win7/8/8.1)

  • * stage_4_repair:telemetry: Add plumbing and notification message for upcoming Windows 10 telemetry purge code

  • * stage_2_de-bloat:oem: Significant additions to debloat lists, should greatly increase effectiveness of Stage 2

  • ! stage_7_wrap-up:resume: Fix erroneous addition of Safe Mode check to Dry Run cleanup code

  • * Subtool updates

v6.6.0 (2015-09-07)

  • + stage_3_disinfect:wusa: Add removal of bad Windows Updates that backport "telemetry" (user tracking) from Windows 10 to Windows 7 and 8. Use -str flag or associated SKIP_TELEMETRY_REMOVAL variable to skip this. See the entry for this action on the list of full Tron actions in the Instructions file for more information

  • + tron.bat:prep: Add prompt to automatically reboot to Safe Mode w/ Networking if we detect we're not in Safe Mode. Thanks to /u/patx35

  • - stage_8_wrap-up:gsl: Remove -gsl flag and associated GENERATE_SUMMARY_LOGS variable. Summary logs are now generated by default

  • ! stage_7_wrap-up:resume: Fix resume-related cleanup; was incorrectly executing in Dry Run mode


Download

  1. Primary method: Download a self-extracting .exe pack from one of the mirrors:

MirrorHTTPSHTTPLocationHost
OfficiallinklinkUS-NY/u/SGC-Hosting

1 | link | link | US-NY | /u/danodemano

2 | link | link | DE | /u/bodkov

3 | --- | link | US-CA | /u/windowswill

4 | link | link | NZ | /u/iDanoo

5 | link | link | FR | /u/mxmod

6 | link | --- | BT Sync mirror | /u/Falkerz (HTTP mirror of the BT Sync repo)

2. Secondary method: Connect to the BT Sync repo to get fixes/updates immediately. Use the read-only key:

    B3Y7W44YDGUGLHL47VRSMGBJEV4RON7IS      <--  NEW KEY !!

*Make sure the settings for your Sync folder [look like this](http://i.imgur.com/CFZp4iz.png) (or [this](http://i.imgur.com/cq8Kw1m.png) on v1.3.x).*

3. Tertiary method: Connect to the SyncThing repo (testing) to get fixes/updates immediately. Instructions here

4. Quaternary method: Source code

All the code I've written is available [here on Github](https://github.com/bmrf/tron/) (Note: this doesn't include many of the utilities Tron relies on to function). If you want to see the code without downloading a big package, or want to contribute to the project, the Git page is a good place to do it.

Command-Line Support

Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.

Usage: tron.bat [-a -c -d -e -er -m -o -p -r -sa -sb -sd -se -sfr -sk
          -sm -sp -spr -srr -ss -str -sw -v -x] | [-h]

Optional flags (can be combined):
 -a   Automatic mode (no welcome screen or prompts; implies -e)
 -c   Config dump (display current config. Can be used with other
      flags to see what WOULD happen, but script will never execute
      if this flag is used)
 -d   Dry run (run through script without executing any jobs)
 -e   Accept EULA (suppress display of disclaimer warning screen)
 -er  Email a report when finished. Requires you to configure SwithMailSettings.xml
 -m   Preserve OEM Metro apps (don't remove them)
 -np  Skip the pause at the end of the script
 -o   Power off after running (overrides -r)
 -p   Preserve power settings (don't reset power settings to default)
 -r   Reboot automatically (auto-reboot 30 seconds after completion)
 -sa  Skip anti-virus scans (MBAM, KVRT, Sophos)
 -sb  Skip de-bloat (OEM bloatware removal; implies -m)
 -sd  Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
 -se  Skip Event Log clearing
 -sfr Skip filesystem permissions reset (saves time if you're in a hurry)
 -sk  Skip Kaspersky Virus Rescue Tool (KVRT) scan
 -sm  Skip Malwarebytes Anti-Malware (MBAM) installation
 -sp  Skip patches (do not patch 7-Zip, Java Runtime, Adobe Flash or Reader)
 -spr Skip page file settings reset (don't set to "Let Windows manage the page file")
 -srr Skip registry permissions reset (saves time if you're in a hurry)
 -ss  Skip Sophos Anti-Virus (SAV) scan
 -str Skip Telemetry Removal (don't remove Windows user tracking, Win7 and up only)
 -sw  Skip Windows Updates (do not attempt to run Windows Update)
 -v   Verbose. Show as much output as possible. NOTE: Significantly slower!
 -x   Self-destruct. Tron deletes itself after running and leaves logs intact

Misc flags (must be used alone):
 -h   Display this help text

Integrity

checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x07d1490f82a211a2; pubkey included). You can use this to verify package integrity.

Please suggest modifications and fixes; community input is helpful and appreciated.


Donations: 1LSJ9qDzuHyRx6FfbUmHVSii4sLU3sx2TF

Quiet ^Professionals


r/usefulscripts • • Jun 30 '15

[POWERSHELL] NinitePS - a powerful powershell wrapper for Ninite Pro

Thumbnail
github.com
38 Upvotes

r/usefulscripts • • Oct 28 '14

[PowerShell] Monthly Report of Exchange Mailbox Sizes & Item Count.

38 Upvotes

https://github.com/Nostalgiac/Scripts/blob/master/MonthlyEmailReport.ps1

Did a quick search and didn't see anything on this sub so thought I'd post one I just wrote up.

I'm a powershell novice so there's no guarantee it's perfect!

Here's what the output looks like: http://i.imgur.com/2CA04aP.png

Just change the mail settings (server, from, to) and set it up as a scheduled task to run on the last day of each month :)


r/usefulscripts • • Nov 15 '12

[POWERSHELL] Deliver someone the ASCII finger

Thumbnail
pastebin.com
38 Upvotes

r/usefulscripts • • Aug 04 '18

[PowerShell] A pure-PowerShell proof-of-concept for getting SMART attributes from a hard drive by letter without any external dependencies.

37 Upvotes

This project was actually just an experiment to see if I could get a few specific raw SMART attribute values for a larger project. Before this I needed to use programs like smartmontools which don't provide programatically-accessible information to use in other scripts. With a bit of help from /r/Powershell it now spits out information in an attractive and easily manipulable format.

There's a repo here on Github: https://github.com/Fantastitech/GetSmartWin

The script as of posting this is:

$driveletter = $args[0]

if (-not $driveletter) {
    Write-Host "No disk selected"
    $driveletter = Read-Host "Please enter a drive letter"
}

$fulldiskid = Get-Partition | Where DriveLetter -eq $driveletter | Select DiskId | Select-String "(\\\\\?\\.*?#.*?#)(.*)(#{.*})"

if (-not $fulldiskid) {
    Write-Host "Invalid drive letter"
    Break
}

$diskid = $fulldiskid.Matches.Groups[2].Value

[object]$rawsmartdata = (Get-WmiObject -Namespace 'Root\WMI' -Class 'MSStorageDriver_ATAPISMartData' |
        Where-Object 'InstanceName' -like "*$diskid*" |
        Select-Object -ExpandProperty 'VendorSpecific'
)

[array]$output = @()

For ($i = 2; $i -lt $rawsmartdata.Length; $i++) {
    If (0 -eq ($i - 2) % 12 -And $rawsmartdata[$i] -ne "0") {
        [double]$rawvalue = ($rawsmartdata[$i + 6] * [math]::Pow(2, 8) + $rawsmartdata[$i + 5])
        $data = [pscustomobject]@{
            ID       = $rawsmartdata[$i]
            Flags    = $rawsmartdata[$i + 1]
            Value    = $rawsmartdata[$i + 3]
            Worst    = $rawsmartdata[$i + 4]
            RawValue = $rawvalue
        }
        $output += $data
    }
}

$output

I really should comment it and there are obvious improvements that could be made like including the names of the SMART attributes, but for now this is more than I need for my use case. Feel free to post any critiques or improvements.


r/usefulscripts • • Jul 12 '17

[PowerShell] Automate Creating Lab Virtual Machines in Azure with PowerShell

37 Upvotes

r/usefulscripts • • Apr 24 '17

[POWERSHELL] Add your domain to all Office 365 customers safe senders list to ensure your images download in HTML emails

37 Upvotes

For many of our customers, Outlook prevents the automatic downloading of images. It's a bit vain, though this affects how our service ticket messages are displayed to customers. This script will add your domain to the safe senders list for all of your delegated Office 365 tenants.


r/usefulscripts • • Dec 23 '16

[Powershell] [Batch] SysPrep Menu with Post Image Static IP and Join Domain Scripts

Thumbnail
github.com
37 Upvotes

r/usefulscripts • • Jun 04 '21

[PYTHON / TERRAFORM] Reddit bots to evaluate comment sentiment and watch for Deleted/Removed Posts

36 Upvotes

I have two python bots that may be deployed automatically to AWS via terraform:

https://github.com/chadgeary/redditbots

Removalwatch: removalwatch bot periodically checks for removed posts and store the removals. Deployed automatically via Terraform, removalwatch uses Cloudwatch EventBridge (scheduler), Lambda (execution), and DynamoDB (storage). Lambda interfaces with Reddit via the praw python module.

Sentiment: sentiment bot periodically scrapes (sub)reddit posts' top comments, evaluate sentiment (positive, neutral, negative, mixed) if a comment containts target word(s) and store the results. Deployed automatically via Terraform, sentiment uses Cloudwatch EventBridge (scheduler), Lambda (execution), Comprehend (sentiment), and DynamoDB (storage). Lambda interfaces with reddit via the praw python module.


r/usefulscripts • • Aug 04 '19

[PowerShell] Working with HTML just got better

Thumbnail
evotec.xyz
36 Upvotes

r/usefulscripts • • Aug 23 '18

[PowerShell] PSWinDocumentation - ActiveDirectory to Word/Excel without Word/Excel installed

36 Upvotes

After few weeks of working on new version finally I'm able to give it to you. PSWinDocumentation 0.1. This is still work in progress but it's a leap forward.

There are 3 new features:

  • Allows Exporting to Microsoft Excel (that's right – export same or more data that goes to Word to Excel)

  • Build your Word/Excel document as you want (choose data, visual parts, what you need yourself)

  • Work with big ActiveDirectory Forest/Domain object in PowerShell

The story

Blog post about this release shows most of the features. Overview documentation covers the basics but it holds all the links :-)

How it's done

As with Word, there is no need to have Excel installed. This is thanks to 2 modules PSWriteWord and PSWriteExcel. Both are under development and going step by step on per need basis. I'm aware that there is ImportExcel module but I needed something different that I can build and use for my projects.

Goal for this release

Goal for this release was to provide extensive way to build AD documentation along with export to Excel to provide easier way to filter and work with data. You can run export, fix your domain, change things and simply rerun and have always up to date documentation.

What it covers from ActiveDirectory perspective

// Forest Information - Section Main
ForestInformation,
ForestFSMO,
ForestGlobalCatalogs,
ForestOptionalFeatures,
ForestUPNSuffixes,
ForestSPNSuffixes,
ForestSites,
ForestSites1,
ForestSites2,
ForestSubnets,
ForestSubnets1,
ForestSubnets2,
ForestSiteLinks,
// Domain Information - Section Main
DomainRootDSE,
DomainAuthenticationPolicies, // Not yet tested
DomainAuthenticationPolicySilos, // Not yet tested
DomainCentralAccessPolicies, // Not yet tested
DomainCentralAccessRules, // Not yet tested
DomainClaimTransformPolicies, // Not yet tested
DomainClaimTypes, // Not yet tested
DomainFineGrainedPolicies,
DomainGUIDS,
DomainDNSSRV,
DomainDNSA,
DomainInformation,
DomainControllers,
DomainFSMO,
DomainDefaultPasswordPolicy,
DomainGroupPolicies,
DomainGroupPoliciesDetails,
DomainGroupPoliciesACL,
DomainOrganizationalUnits,
DomainOrganizationalUnitsBasicACL,
DomainOrganizationalUnitsExtended,
DomainContainers,
DomainTrusts,
// Domain Information - Group Data
DomainGroupsFullList, // Contains all data
DomainGroups,
DomainGroupsMembers,
DomainGroupsMembersRecursive,
DomainGroupsSpecial,
DomainGroupsSpecialMembers,
DomainGroupsSpecialMembersRecursive,
DomainGroupsPriviliged,
DomainGroupsPriviligedMembers,
DomainGroupsPriviligedMembersRecursive,
// Domain Information - User Data
DomainUsersFullList, // Contains all data
DomainUsers,
DomainUsersAll,
DomainUsersSystemAccounts,
DomainUsersNeverExpiring,
DomainUsersNeverExpiringInclDisabled,
DomainUsersExpiredInclDisabled,
DomainUsersExpiredExclDisabled,
DomainUsersCount,
DomainAdministrators,
DomainAdministratorsRecursive,
DomainEnterpriseAdministrators,
DomainEnterpriseAdministratorsRecursive,
// Domain Information - Computer Data
DomainComputersFullList // Contains all data