r/usefulscripts • • Oct 21 '20

PowerShell: Check if Program or Update is Installed and Download with BITS and Install

19 Upvotes

I recently wrote a PowerShell script for Windows that will check if a program or update is installed and, if not, download it using BITS in low priority, verify the download hash, and then install it and copy the verbose log to a central repository. The example is for the current latest Microsoft Surface Pro 7 firmware, but it can be adapted for just about any installer. 

https://www.grimadmin.com/article.php/powershell-check-program-update-installed-download-bits-install


r/usefulscripts • • Sep 08 '19

[PowerShell] Making PowerShellGallery modules Portable

19 Upvotes

Recently I've been working on a new PowerShell module. One of the tasks I've picked for this PowerShell module was for it to be portable when access to PowerShellGallery is blocked or otherwise inconvenient.

So I wrote this simple command that can help me do just that: https://evotec.xyz/making-powershellgallery-modules-portable/


r/usefulscripts • • Feb 26 '19

[Question] [Powershell] Best way to host and allow for scripts to be run via web browser

19 Upvotes

Hey all, just a general inquiry to you guys/gals.

I have written a few pretty handy scripts for myself and a few of my friends but of course they only exist and can be ran if the script is downloaded locally.

Is there a nice self-hostable way for me to allow someone to access and run the script from a web browser externally? Ideally behind a user login or maybe in a safe sandbox environment.

I know the long solution is to re-write the scripts into a language more suitable for webpages, but for the time being, any advice?

Thanks in advance!


r/usefulscripts • • Feb 23 '19

[CMD] boilerplate - A template based file generator for Windows scripts.

19 Upvotes

Hello, everyone. I recently came across Linux tools Cookie and Cookiecutter. Both are template-based file generators to aid in development of projects for various languages. They looked really good and useful for developers and so I thought I'd make a similar thing for Windows scripters and I've chosen to call it boilerplate.

Boilerplate is still in its infancy and for now it allows template-based generation of Batch, Powershell, VBscript, JScript and HTA scripts.

I'd really appreciate feedback from the Windows scripting community.

How to get boilerplate

PS: After posting this, I discovered Plaster. It's a really good Powershell module that does this so Powershell enthusiasts be sure to check it out.


r/usefulscripts • • Feb 06 '19

[PowerShell] How to find different server types in Active Directory

Thumbnail
evotec.xyz
19 Upvotes

r/usefulscripts • • Oct 30 '18

[PowerShell] Get-LocalDisk

Thumbnail
sconstantinou.com
19 Upvotes

r/usefulscripts • • Jul 24 '18

[Request] Help with RoboCopy command

19 Upvotes

In my previous post I found a solution.

Now I need to develop the script for the solution.

  • copy files from C:\source_folder\ to C:\target_folder\

  • upon completion of copying the files, move the files that were copied from C:\source_folder\ to C:\archive_folder

This way the source folder is empty but a backup of those files is in an archive folder.

I'm thinking about using RoboCopy for this task with something like:

Robocopy C:\source C:\target

Now I need to move files in the source directory to an archive folder:

Robocopy C:\source C:\archive /move

Can this be completed in one command or does it have to be two?

I would ideally use a scheduled task to run the script once a day.

Any help would be appreciated.


r/usefulscripts • • Jun 17 '18

[Request] Batch File to zip multiple sets of .BIN and .CUE files

19 Upvotes

I’m looking for a way of using 7Z to zip several files with the same into a .7z/.zip file.

Within my directory I have hundreds of files with differing amounts of ‘tracks’ like so;

    Zebrafile.cue
    Zebrafile (Track 1).bin
    Zebrafile (Track 2).bin
 
    Donkeyfile.cue
    Donkeyfile (Track 1).bin
    Donkeyfile (Track 2).bin
    Donkeyfile (Track 3).bin
 
    Extradonkeyfile.cue
    Extradonkeyfile (Track 1).bin

And I need a way of zipping these files together automatically so I just end up with

    Zebrafile.zip
    Donkeyfile.zip
    Extradonkeyfile.zip

I guess the script would have to match the whole filename from the start UP TO the space before the opening bracket "(" somehow! The only variable after that match would be the number of the track "(Track X)"

Would anybody be able to point me in the right direction? I have seen other batch files which get close, but I'm still unsure of how to get the batch file to take into account the changing Track #. Many thanks!


r/usefulscripts • • May 14 '18

[Request] List expiring SSL Certificates for all Servers

19 Upvotes

Hello,

I am wondering if anyone has a script that can scan a domain or multiple subnets and list out expiration dates for SSL certificates. Email Warning would be awesome but whatever you guys have would be great!


r/usefulscripts • • Apr 09 '18

[Script Sharing Powershell] Write-Color - wrapper around Write-Host

19 Upvotes

This is a script I've written 2 years ago and today I'm releasing new updated version of it. Essentially it allows you to create nice looking scripts without effort.

Description: https://evotec.xyz/write-color-2-year-anniversary-edition-version-0-3/

Support/Latest code: https://github.com/EvotecIT/PSWriteColor

PowerShellGalery: https://www.powershellgallery.com/packages/PSWriteColor/ (lately published as module): Install-Module PSWriteColor (usage Write-Color or wc)


r/usefulscripts • • Nov 07 '17

Script to find Broken SCCM Clients with Powershell

19 Upvotes

Hello, I am trying to find a script that finds broken SCCM Clients on my network. I was wanting to just run it to all of the computers in Active Directory.

After a long time of trying to find it on google, all everything gives me is "SCCM 2012 already has that function built into it." We do not have SCCM 2012, we have SCCM Current Branch.

I have already gotten a script that fixes the broken clients and it works, I just need a script to be able to find the broken clients.

Any help would be greatly appreciated. Thank you.


r/usefulscripts • • Oct 19 '17

Suppress warning when calling a Import in powershell. [POWERSHELL]

19 Upvotes

[POWERSHELL] I have noticed sometimes when you run a import-pssession or import-module you will receive an warning which is common, Some users like myself are aware of the warning and dont like to see it in the script like myself so the below will suppress it warning users will sometimes receive

"WARNING: The names of some imported commands from the module 'tmp_biyt2uhj.f5s' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Ve rb.

ModuleType Version Name ExportedCommands


Script 1.0 tmp_biyt2uhj.f5s {Add-ADPermission, Add-AvailabilityAddressSpace, Add-ContentFilterPhrase, Add-Databas..."

But if you add the -disablenamechecking > null it will be clean like the below. Import-Module -Name “c:\homelab\2.0\Microsoft.Exchange.WebServices.dll” $exchangesession = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri http://dact007.homelabco.com/PowerShell/ -Authentication Kerberos Import-PSSession $exchangesession -DisableNameChecking > $null

The result is nice and clean with no error and go straight to the script.


r/usefulscripts • • Aug 18 '17

[REQUEST]Set litigation hold across multiple tenants(365)

19 Upvotes

Trying to make a script to iterate through our tenants in 365 and set litigation hold(the same across the board). I've got to this point.

$UserCredential = Get-Credential

Import-Module MSOnline

Connect-MsolService -Credential $UserCredential

$Tenants = Get-MsolPartnerContract -All

$alldomains = $Tenants | foreach {$Domains = $_.TenantId; Get-MsolDomain -TenantId $Domains}

$domain = $alldomains.name


foreach ($tenant in $domain){

	$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid?DelegatedOrg=$tenant -Credential $UserCredential -Authentication Basic -AllowRedirection
	
	Import-PSSession $Session
	#this is just a test to see if it works
	get-mailbox
	Remove-PSSession $Session

}

Obviously i will replace the get-mailbox with the correct code to set the litigation hold, but just for testing i'm using get-mailbox.

The issue i'm having I have is it seems to just be going over the same tenant over and over, not going to the next tenant.


r/usefulscripts • • Jul 31 '17

Need powershell help

19 Upvotes

SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO

$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = push-location -Path "\\server\share"
$watcher.Filter = "*.pdf*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true  

DEFINE ACTIONS AFTER AN EVENT IS DETECTED

$action = { $path = $Event.SourceEventArgs.FullPath
            $changeType = $Event.SourceEventArgs.ChangeType
            $logline = "$(Get-Date), $changeType, $path"
            Add-content "C:\source\log.txt" -value $logline
          }    

DECIDE WHICH EVENTS SHOULD BE WATCHED

Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5}

I'm completely new to powershell and I would like to set a variable equal to a the push-location section for a fileshare and then after the add-content portion I would like to be able to run a cmd to rename pdfs that have " " spaces to "_" within that directory

the push-location was put in by me as I don't believe I can do a network path there


r/usefulscripts • • May 23 '17

[Request][Batch] A batch file that will check all my drivers for updates

19 Upvotes

I was wondering if it's possible to make a batch file that will check each driver if it needs an update and then automatically install it.


r/usefulscripts • • Feb 07 '17

[POWERCLI] Update VMware Tools

19 Upvotes

This could probably stand to be improved in various ways, but this is a pretty basic script I put together yesterday that updates VMWare Tools using PowerCLI.

https://www.vmware.com/support/developer/PowerCLI/

I wanted to exclude hosts that already had an up-to-date set of tools installed so I included the 'where' statement to filter them out.

I've also included the 'noreboot' flag (self-explanatory) and the 'runasync' command (runs upgrades in parallel).

connect-viserver <IP / Hostname>

foreach ($VM in (get-vm | get-vmguest | where {$_.ToolsVersion -notlike "10.*"}))
{
    update-tools -vm $VM.VmName -noreboot -runasync
}

The only issues I had when I rolled the tools out, were that DNS (and a few other things) broke on my Domain Controllers, requiring them to be rebooted.

Didn't work on Solaris or SUSE. Worked on RedHat, CentOS, Windows, etc.

 

EDIT: Unfortunately, it doesn't do fresh installs of tools. I suspect this could be scripted too using a combination of mount-tools (cmdlet built into PowerCLI) and invoke-command / PSExec (cmd /c D:\VMToolsSetup.exe /S).


r/usefulscripts • • Dec 04 '16

[REQUEST] Windows script to change keyboard layout to DVORAK on a single (active) user.

19 Upvotes

Hey guys, I was wondering if anyone could help me with a script. I need a portable script that I can bring use to quickly swap to dvorak (and subsequently one that swaps back to qwerty) on any given Windows 8 or Windows 10 machine. This would be a breeze to do in a linux environment, but I got thrusted into windows work temporarily and it would save an huge amount of time to be able to swap with a single run of a bat! Thanks!


r/usefulscripts • • Aug 25 '16

[PowerShell]Client hardware/software inventory remotely

19 Upvotes

A script I put together for those that don't have access to Enterprise tools like SCCM to do this for them.

http://www.signalwarrant.com/2016/08/25/remote-computer-inventory-powershell/


r/usefulscripts • • Jul 26 '16

[POWERSHELL] Get all email addresses and identities in AD

19 Upvotes

I've created a monster and if you could critique my code, then I would greatly appreciate it. This script will basically build a $results object array that contains SamAccountNames and anything with a "@" found in AD in user properties specified in the $searchfilter and $properties.

Code here


r/usefulscripts • • May 09 '16

[REQUEST] Script that deletes all files ending in mp4 and avi on multiple drives

19 Upvotes

I was wondering if theres a way to remove all mp4 and avi on something like drives E:, D:\ and F:\


r/usefulscripts • • Jan 19 '16

[CSV File] FCC Telemarketer and RoboCall Blacklist for Google Contacts 01/19/2016

Thumbnail
pastebin.com
19 Upvotes

r/usefulscripts • • Jan 17 '16

Set power settings via powershell without powercfg.exe

19 Upvotes

Useful if you want to set power properties in WinPE or without relying on powercfg.exe, such as in a generic OS deployment (SCCM, MDT).

http://pastebin.com/nWVVJpff

Note, I am hardly a powershell expert, so there is definitely a more efficient way to do this. I just was sick of posts that said "use powershell to set power settings" that all referenced powercfg.exe. It's no different from the same damn command line method used for the last 15 years. Of course, that means that this script could probably easily be changed back into VB itself, but oh well - mission accomplished. To hell with guids to set power settings.


r/usefulscripts • • Oct 19 '15

[BATCH] Very quick and useful file locator script

Thumbnail
pastebin.com
19 Upvotes

r/usefulscripts • • Aug 19 '15

[Batch] MoveIIS7Root.bat Need to move IIS7 Root to another drive?

Thumbnail
pastebin.com
19 Upvotes