r/usefulscripts • • Nov 30 '15

[powershell] Bypass import-module Active Directory

21 Upvotes

Hello,

I was recently working on a powershell script to deploy office 365 from a DFS share. Trying to make it a simple point and click installation where it would go into AD and find out what security group the current user was a member of (and use the appropriate config file). Set it up on my computer, no problems: when i ran on test computer, realized that they didn't have the active directory module. Didn't see any quick and easy ways of deploying the module, so after some research, found out that i can get user info from WinNT and use that to get users LDAP info. Had a bit of grief tho, as all the how-to guides wanted to manually plug in the full distinguished name path (cn=JOHN,ou=users,dc=domain,dc=com). Much to lazy to do that (and didn't want to keep having to go back and update the script). Used the handy dandy objectSID values used by both WinNT and LDAP to pull the information and vola: don't need active directory module

TL,DR: use these commands instead of the active directory module


<#gets WinNT info based off current user. Missing lots of info compared to LDAP#>

$dom = $env:userdomain

$usr = $env:username

$ADuser = ([adsi]"WinNT://$dom/$usr,user") | select *

$binarySID = $ADuser.ObjectSid.Value #Get SID, used by both LDAP and WinNT

<# convert to string SID#>

$stringSID = (New-Object System.Security.Principal.SecurityIdentifier($binarySID,0)).Value

$binarySID #shows difference between binary value pulled by default and string value

$stringSID #need it in this form for ldap

$user =[adsi] "LDAP://<SID=$stringSID>" | select *

$user


Don't need to adjust for your domain (I think), just copy and paste

XOXOXO


r/usefulscripts • • Oct 21 '15

[BATCH] Fahrenheit to Celsius (& C-F) calculator

Thumbnail
pastebin.com
21 Upvotes

r/usefulscripts • • May 26 '15

[Request][Batch/PowerShell] Made a script to allow our Operations team query the status of Exchange DAG. Want to streamline it into one file, not a batch + PS1 that I was able to hack together.

Thumbnail
pastebin.com
21 Upvotes

r/usefulscripts • • Sep 23 '13

[VBSCRIPT] GPUpdate All Domain Computers

21 Upvotes

I wrote this a while ago. I know there are similar ones out there but this is what I use and have been using. This requires you to have PSTools downloaded and extracted to C:\TOOLS\ for this to work as is.

The script should be run on a DC and as a Domain Admin. This will loop through AD and create a separate instance for each computer and run GPUpdate /force on the system.

PSTools Download: http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx

EDIT: Script PasteBin: http://pastebin.com/9LjrBmhr


r/usefulscripts • • Sep 23 '13

[BATCH] Who's On? (a remote workstation)

21 Upvotes

Summary

Remotely queries a system and tells you who's logged on to it. Can use one of three available methods for checking:

  • WMIC (most reliable, however provides the least information)

  • Windows_query_user (requires Windows Vista and up; doesn't work on XP)

  • PsLoggedon (requires PsLoggedon.exe from sysinternals)

Usage

Run from a command prompt that has admin credentials on the remote computer you want to check.

Edit the "METHOD" variable on line 29 to change the method of checking if you want. By default it's set to the WMIC method, which I've found to be the most reliable.


Download

v1.7.1 (2014-09-08)

  • * Overhauled Date/Time conversion so we can handle ALL versions of Windows using ANY local date-time format


r/usefulscripts • • Mar 20 '23

Fix Vlookup Links in Excel - Power Shell

20 Upvotes

My company is about to do a data migration and it's going to break all of the finance departments vlookups in there excel files. This is a script that I put together to help correct those instead of purchasing a copy of link fixer. Feel free to use it as you would like:
https://pastebin.com/4tP1eDfH


r/usefulscripts • • Apr 07 '21

[QUESTION] Simple bash script, using 'expect', to download backups off a server, will connect and only dl 10-15mb of the 10gb file before exiting. Help?

20 Upvotes

Here is the script, sensitive parts x'ed out

!/usr/bin/expect -f set timeout 10 spawn bash -c "scp -P xxxxxxxxx/backup.zip /xxxxxxxxx/Backups/"

securely log into server and download the back.zip file cron job recently created.

expect { "password" { send "xxxxxxxx\r"; exp_continue } }

when prompted script enters the ssh login password.

expect { "100%" {send "exit/r" } }

Once logged in, the download begins, and expect watches for "100%" signalling the download is complete and can exit out of the ssh session.

Log in works, the download starts, but the script dumps me back to my bash terminal prompt after only a few seconds, downloading only 10-15 mbs of the backup file.


r/usefulscripts • • Jun 12 '20

[Terraform] with IAM+Lambda+Cloudwatch for EC2 Backups

Thumbnail
github.com
20 Upvotes

r/usefulscripts • • Aug 25 '19

[PowerShell] Comparing two or more PowerShell objects visually using Out-HTMLView/PSWriteHTML

20 Upvotes

Today, I've for you, a completely new feature of Out-HTMLView/PSWriteHTML PowerShell module. What this feature does, it allows comparing two or more PowerShell objects together.

While normally you would do this with Compare-Object but that gives you only half of the story. In a linked blog post and in that PowerShell Module I went a step ahead and created a visual way to compare two or more PowerShell Objects.

Get-Disk | Out-HtmlView -Compare -HighlightDifferences
Get-ADUser -Filter * -Properties Modified, MemberOf, IsCriticalSystemObject | Select-Object -First 2 | Out-HtmlView -Compare -HighlightDifferences
get-vm | Out-HtmlView -Compare -HighlightDifferences

Make sure to read the blog post as I've described lots of possibilities that can be useful in day to day use. Link to a blog describing features and usage:

https://evotec.xyz/comparing-two-or-more-objects-visually-in-powershell-cross-platform/

Sources:


r/usefulscripts • • Sep 30 '17

Enable Mailbox Auditing for all O365 users in all tenants using delegated administration

Thumbnail
gcits.com
20 Upvotes

r/usefulscripts • • Apr 12 '17

[AHK] GUI/script to retrieve Quickbooks product license information

20 Upvotes

The v2 script | A screenshot | A quck'n'dirty icon

On a live system, you can just use F2 while in Quickbooks to get this information. On an offline system, it's not as easy.
Quickbooks stores its product licensing information in an XML file in the ProgramData directory, (specifically C:\ProgramData\COMMON FILES\INTUIT\QUICKBOOKS\qbregistration.dat). While it's easy enough to go into that directory to retrieve the XML file and parse the information manually, this just makes it a little bit easier.

edit: Uploaded v2 script that pulls multiple keys, and fixed some issues with the original script. (The original script)


r/usefulscripts • • Jan 16 '17

[Batch] A small pop-up window where a user can select Time Zone.

Thumbnail
pastebin.com
20 Upvotes

r/usefulscripts • • May 05 '16

[Request] Bash - Auto delete files older than X days and email what was deleted

20 Upvotes

We back up images of client machines (mainly vhd files) to a FreeNAS whenever they are decommissioned or re-imaged, would like some help setting up an auto-retention script via a cron for each folder, e.g. one script that will delete files after 30 days for the workstations folder, and one that will delete after 1yr for the servers folder, then email on completion what was deleted, and if nothing was deleted, do not email.

If possible, another addition to the servers script that would be nice - a "warning" saying "in 7 days these server images will be deleted", or something along those lines. If not, we can just pull it from snapshots.


r/usefulscripts • • May 21 '15

[POWERSHELL] Bulk Add SMTP Addresses to Office 365 Mailboxes

Thumbnail
exchangeserverpro.com
20 Upvotes

r/usefulscripts • • Apr 21 '15

[PowerShell] Enabling/Disabling Java (NPAPI) in Google Chrome by Using the Registry (x-post /r/powershell)

Thumbnail
adminarsenal.com
20 Upvotes

r/usefulscripts • • Mar 11 '15

Simple Wordpress Bash Backup Script - Hauck Daniel Hauck Daniel

Thumbnail hauck-daniel.de
20 Upvotes

r/usefulscripts • • Feb 17 '15

[POWERSHELL] Batch Password Reset Tool for Office 365 (GUI)

Thumbnail
psnuggets.com
20 Upvotes

r/usefulscripts • • Jul 23 '14

[BATCH] Two-liner to get any Windows date, regardless of local time format, into ISO standard date format (yyyy-mm-dd)

20 Upvotes

Here's a two-liner I've been using to get the Windows date into the ISO standard format (yyyy-mm-dd) and seems to work regardless which version of Windows is running, or what local time settings are configured.

FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%

This will set two variables. One, %CUR_DATE%, contains the following ISO standard format date:

yyyy-mm-dd

The second, %DTS%, contains the full DateTime stamp, like so:

20140723122146.999000-420

I tried making it a one-liner by stacking the commands with &&, but it didn't seem to set CUR_DATE correctly, so I resorted to the two-line version. Hope this helps.


r/usefulscripts • • Jan 14 '14

VBScript vs Powershell

20 Upvotes

I have previous experience with PHP, but VBScript and Powershell are new to me. I would appreciate your suggestions regarding whether I should learn VBScript, Powershell, or both...and good starting resources to learn the scripting language.

I'd also appreciate tips on IDE for writing and testing.


r/usefulscripts • • Apr 10 '13

[BATCH] Add IP-based printer

20 Upvotes

Yesterday I shared a script that removes printers, so today I'm sharing a script that adds IP-based printers. It checks for OS version (XP or 7) and then installs the appropriate driver. It can also rename the printer, add a location, and make it the default printer if you wish.

It's heavily commented so hopefully it makes sense. If it doesn't, please feel free to ask any questions.

Pastebin link here. Have fun.


r/usefulscripts • • Nov 17 '12

[BASH] Shortcut for SSH login

20 Upvotes

Create this script in your path, call it 'ssh-argv0'

#!/bin/sh
 exec ssh "${0##*/}" "$@"%   

Symbolic link a host name to the script

# ln -s hostname.company.com ssh-argv0

Now login to the host ..

# hostname.company.com

Mix in a dash of tab completion and you're set.


r/usefulscripts • • Aug 07 '23

GitHub - Mido: Rufus Windows ISO Downloader (Fido) Ported to Linux

Thumbnail
github.com
19 Upvotes

r/usefulscripts • • Jan 15 '23

[VBScript] Explorer Window Folder Paths

Thumbnail
pastebin.com
19 Upvotes

r/usefulscripts • • Nov 10 '20

[PowerCLI] Copy roles, users & permissions from one ESXi host to another

Thumbnail
gist.github.com
19 Upvotes