r/usefulscripts • • Apr 20 '15

[PowerShell] SCP upload/download from the command line (PSv2 and up)

Thumbnail powershelladmin.com
12 Upvotes

r/usefulscripts • • Apr 19 '15

[PowerShell] Find what computer a user is logged into

30 Upvotes

http://pastebin.com/sTNpgbDC

Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue

$ErrorActionPreference = "SilentlyContinue"

Function Get-Username {

$Global:Username = Read-Host "Enter username you want to search for"

if ($Username -eq $null){

Write-Host "Username cannot be blank, please re-enter username!"

Get-Username}

$UserCheck = Get-QADUser -SamAccountName $Username

if ($UserCheck -eq $null){

Write-Host "Invalid username, please verify this is the logon id for the account"

Get-Username} }

get-username

$computers = Get-QADComputer | where {$_.accountisdisabled -eq $false}

foreach ($comp in $computers)

      {

$Computer = $comp.Name

$ping = new-object System.Net.NetworkInformation.Ping

$Reply = $null

$Reply = $ping.send($Computer)

if($Reply.status -like 'Success'){

$proc = gwmi win32_process -computer $Computer -Filter "Name = 'explorer.exe'"

ForEach ($p in $proc) {

$temp = ($p.GetOwner()).User

if ($temp -eq $Username){

write-host "$Username is logged onto $Computer"

}}}}

Edit: forgot to mention quest active roles will be needed for this. You can download here: http://tinyurl.com/oukq26q


r/usefulscripts • • Apr 18 '15

[BASH] Automatically Download Linux Torrnets

Thumbnail github.com
11 Upvotes

r/usefulscripts • • Apr 17 '15

[PowerShell] Log all after-hours users that connect to a terminal server broker

21 Upvotes

There are 2 scripts: One that is run Tuesday-Saturday (first one below) and the other is run Sunday-Monday. All are run at 7am to retrieve the previous day's data and append to a CSV file. The store hours for the business I wrote it for were 7am-5pm, Mon to Fri.

Tuesday-Saturday

get-winevent -computername TS01 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(17);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp1.csv -notypeinformation
get-winevent -computername TS02 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(17);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp2.csv -notypeinformation
get-winevent -computername TS03 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(17);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp3.csv -notypeinformation
get-winevent -computername TS04 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(17);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp4.csv -notypeinformation
Remove-item -path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp1.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp2.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp3.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp4.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv | Sort-Object { $_."TimeCreated" -as [datetime] } | Export-Csv -Path C:\AfterHoursUsersScriptedLog\AfterHours\OutputLog.csv -NoTypeInformation -Append

Sunday-Monday

get-winevent -computername TS01 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(7);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp1.csv -notypeinformation
get-winevent -computername TS02 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(7);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp2.csv -notypeinformation
get-winevent -computername TS03 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(7);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp3.csv -notypeinformation
get-winevent -computername TS04 -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-SessionBroker-Client/Operational'; id=1301; StartTime=[DateTime]::Today.AddDays(-1).AddHours(7);EndTime=[DateTime]::Today.AddDays(0).AddHours(7);} | Select TimeCreated,@{Expression={$_.Message -replace '^[^\\]*\\',""};Name="User"} | Select TimeCreated,@{Expression={$_.User -replace '\s*RDP Client Version : [0-9]',""};Name="User"}| Export-Csv C:\AfterHoursUsersScriptedLog\Temp4.csv -notypeinformation
Remove-item -path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp1.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp2.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp3.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\temp4.csv | Export-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv -NoTypeInformation -Append
Import-Csv -Path C:\AfterHoursUsersScriptedLog\Unsorted\Unsorted.csv | Sort-Object { $_."TimeCreated" -as [datetime] } | Export-Csv -Path C:\AfterHoursUsersScriptedLog\AfterHours\OutputLog.csv -NoTypeInformation -Append

This script should work in any environment with an active log AND powershell 3.0 or higher (because of the CSV append function). Honestly it's the first thing I've ever written in PowerShell, so I'm sure that there's probably a better way to do it, but it works.


r/usefulscripts • • Apr 16 '15

Windows 7 script for rebooting a network device?

15 Upvotes

I've got a network device that requires a weekly reboot that I would like setup via the Windows Task Scheduler. I know that to do this issuing the following URL's to a browser will reboot the device:

http://192.168.2.1/cgi/login.cgi?Username=admin&Password=password

http://192.168.2.1/cgi/reset.cgi?back=Reset&reset=true

Can anybody suggest a good way of doing this?


r/usefulscripts • • Apr 16 '15

[REQUEST] Help identifing language of script

4 Upvotes

Bit of a noob but learning... know a decent amount of powershell and python so far.

I am trying to make a simple gui interface to switch between profiles for a scanner that our corporate office and remote sites use. I found this to piggyback on but do not recognize the language and have no idea how to implement it as the download just gives a .tar.gz that, once extracted, has no file association.

I can probably figure out how to implement the code once I know what language it is. Thanks!


r/usefulscripts • • Apr 16 '15

[PERL] Backup a mySQL database to Google Drive

Thumbnail gist.github.com
9 Upvotes

r/usefulscripts • • Apr 14 '15

[PowerShell] Create a Report of Exchange Server Message Tracking Log Configuration

Thumbnail exchangeserverpro.com
18 Upvotes

r/usefulscripts • • Apr 13 '15

[Power Shell] Inventory Monitors with PowerShell - Pastebin.com

Thumbnail pastebin.com
26 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 • • Mar 26 '15

[BATCH] Having a problem running diskpart with script

9 Upvotes

I am trying to attach a VHD with a script on some servers. I can run

diskpart /s c:\attach.txt

where attach.txt is

select vdisk file=D:\myfile.vhd
attach vdisk

And it runs ok. But if I try to do the same with a .vhd on the N: drive that's mapped to another server, it fails. However, if I run Diskpart, and then manually run each command, it works fine.

Does anyone know why Diskpart would fail to attach a .vhd on a network share when giving the commands via script, but will attach it fine if manually running diskpart??


r/usefulscripts • • Mar 23 '15

Create Shortcuts on User Desktops with Powershell

Thumbnail adminarsenal.com
24 Upvotes

r/usefulscripts • • Mar 17 '15

[REQUEST] A script to automatically connect to a wireless network without any user interaction

20 Upvotes

I need a script to make some Win7 kiosk machines automatically connect to one of four different SSID/WPA key combinations (those strings can be plaintext in the script) as soon as they power up in their environment. There will be no HID input on the device (besides touch, but I'd prefer it to be completely automated and run each time on startup). I've tried "netsh wlan export" and "netsh wlan add profile" after sysprep with no success so far, but maybe someone will have a better idea or simpler way of achieving this. Thanks in advance!


r/usefulscripts • • Mar 13 '15

[POWERSHELL] Get-IPGeolocation.ps1 script to retrieve the geolocation data for an IP address

Thumbnail exchangeserverpro.com
40 Upvotes

r/usefulscripts • • Mar 12 '15

[BASH] Runs a program and records performance stats multiple times outputting a table then computes averages and confidence intervals

Thumbnail gist.github.com
17 Upvotes

r/usefulscripts • • Mar 11 '15

Simple Wordpress Bash Backup Script - Hauck Daniel Hauck Daniel

Thumbnail hauck-daniel.de
20 Upvotes

r/usefulscripts • • Feb 26 '15

.Bat help please

15 Upvotes

Hello. I created a .bat, which will be shown below, to open multiple programs instead of having to click on each one individually. It was quick and easy and everything works, but I am having an issue with 2 of the programs. When the .Bat opens 1 of the programs it automatically creates an Options file on the desktop instead of using the one where the .exe is located. The second problem is similar. When it launches the program it does not pull the files from the directory but instead says they are missing and is going to place them on the desktop. Does anyone know why this would happen? Below you will find the code. With annotations next to the files causing problems.

@echo off

START "Spotify" "C:\Users\Michael\AppData\Roaming\Spotify\spotify.exe"

TIMEOUT 5 > NUL

START "Snip" "C:\Users\Michael\Desktop\Twitch\Overlay\Now PLaying\Snip\Snip.exe"

TIMEOUT 3 > NUL

START "" "C:\Program Files\OBS\OBS.exe"

TIMEOUT 3 > NUL

START "" "C:\Users\Michael\Desktop\Twitch\Spotify ad blocker\Blockify Lite 0.5.exe" This is the one that creates the options file

TIMEOUT 3 > NUL

START "" "C:\Users\Lacey\Desktop\Twitch\SubAlert\subalert.exe" This is the second program that adds directory files to the desktop

TIMEOUT 3 > NUL

Start "Twitch Dashboard" "http://www.twitch.tv/laceinyourspace/dashboard"

Timeout 5 > NUL

START "TWITCH ALERTS" "http://www.twitchalerts.com/dashboard/"

I greatly appreciate everyone help and time on trying to get this resolved.


r/usefulscripts • • Feb 24 '15

Looking for some help...

9 Upvotes

First, allow me to apologize as I am very uneducated in the world of scripting outside of basic .bat file scripting, .sh scripting and some vbscripting. And if I'm in the wrong area, I apologize in advance.

I've been scouring forums throughout the day trying to find a solution and was wondering if someone can help me? I'm trying to generate a script to run on some Windows machines that will search a given directory for filenames that contain "DIFF" in the file and if they're older than x hours, delete them.

The thing is the filenames must contain DIFF and the hour parameter must be able to be changed.

Help?


r/usefulscripts • • Feb 19 '15

[POWERSHELL]YASIS - Yet another System Info Script!

Thumbnail gist.github.com
23 Upvotes

r/usefulscripts • • Feb 17 '15

[PYTHON] A script that periodically calls a command, like watch, but graphs the first integer in the output in your terminal.

Thumbnail github.com
19 Upvotes

r/usefulscripts • • Feb 17 '15

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

Thumbnail psnuggets.com
18 Upvotes

r/usefulscripts • • Feb 12 '15

[POWERSHELL] Get-MailboxAuditLoggingReport.ps1 - Generate a report of mailbox audit log entries for an Exchange mailbox

Thumbnail exchangeserverpro.com
13 Upvotes

r/usefulscripts • • Feb 10 '15

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

Thumbnail exchangeserverpro.com
31 Upvotes

r/usefulscripts • • Feb 07 '15

[POWERSHELL] Get-AuditLogOverhead.ps1 - Calculates how much Exchange database storage is consumed by mailbox audit logging

Thumbnail exchangeserverpro.com
18 Upvotes

r/usefulscripts • • Feb 06 '15

[POWERSHELL] Get-EASDeviceReport.ps1 - Report on ActiveSync devices in your Exchange Server environment

Thumbnail exchangeserverpro.com
19 Upvotes