r/usefulscripts • • Mar 17 '15

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

18 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 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
18 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 • • Jul 21 '14

[POWERSHELL] Windows Server Backup Email Report

Thumbnail
github.com
18 Upvotes

r/usefulscripts • • Jun 03 '14

[VBScript] Scan Active Directory OU and Report Information (Logged In User, IP Address and more!) [SCRIPT UPDATE]

Thumbnail
pastebin.com
18 Upvotes

r/usefulscripts • • Dec 29 '13

[PYTHON] Automated Backup System for Websites

Thumbnail abs-for-websites.sourceforge.net
18 Upvotes

r/usefulscripts • • Nov 15 '12

[SQLSERVER] Fail over all mirrored databases

Thumbnail
pastebin.com
18 Upvotes

r/usefulscripts • • Feb 28 '24

How can I automate my task

17 Upvotes

I have task involving 200-300 servers

I am required to run a handful of commands and take a screenshot for the output Screenshots only, no text And I have to do them individually

Meaning: Run Command A

Wait for output Screenshot output Save screenshot

Run command B

Wait for output Screenshot output Save screenshot

——

I will be accessing these servers via a windows jump host, in which I can use any shell application such as putty or mobaxteme

All the username and passwords to access the servers are the same

The series of commands for all the server are also the same

Limitations and availablities

No admin rights on jump host, so only portable application are available(not officially) so yhr application has to be potable and to stay in my thumb drive

I cannot install any application on the AIX servers either

I can scp/ssh from one AIX server to the other in the whole subnet

What I intend to accomplish, it doesn’t have to exact this is just want I can think off at the moment The end goal are the screenshots

Example : gather screenshots on dir size

  1. login to the server via terminal

  2. run command ‘df -g’

  3. wait for output

  4. screenshot output

  5. save output with a specific file name to a specific folder

  6. close terminal

Proceed to next server till 300th server rinse and repeat till all requested screenshots

So far I am able to automate logging in and run the command using a simple batch script which launches putty.exe

However I have still yet to figure out how can I incorporate automating taking the screenshots

Does anyone have any tips ? Or suggestions?


r/usefulscripts • • Sep 03 '23

[PowerShell] Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML

17 Upvotes

I've written a new blog post about a new feature in PSWriteHTML that lets you create HTML reports but mix it up with markdown content. This allows you to choose your preferred way to create content.

Here's an example showing tables, calendar, logo and markdown. Hope you enjoy this one

$ProcessSmaller = Get-Process | Select-Object -First 5

New-HTML {
    New-HTMLTabStyle -BorderRadius 0px -TextTransform capitalize -BackgroundColorActive SlateGrey
    New-HTMLSectionStyle -BorderRadius 0px -HeaderBackGroundColor Grey -RemoveShadow
    New-HTMLPanelStyle -BorderRadius 0px
    New-HTMLTableOption -DataStore JavaScript -BoolAsString -ArrayJoinString ', ' -ArrayJoin

    New-HTMLHeader {
        New-HTMLSection -Invisible {
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Class 'otehr' -Width '50%'
            }
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Width '20%'
            } -AlignContentText right
        }
    }
    New-HTMLSection {
        New-HTMLSection -HeaderText 'Test 1' {
            New-HTMLTable -DataTable $ProcessSmaller
        }
        New-HTMLSection -HeaderText 'Test 2' {
            New-HTMLCalendar {
                New-CalendarEvent -Title 'Active Directory Meeting' -Description 'We will talk about stuff' -StartDate (Get-Date)
                New-CalendarEvent -Title 'Lunch' -StartDate (Get-Date).AddDays(2).AddHours(-3) -EndDate (Get-Date).AddDays(3) -Description 'Very long lunch'
            }
        }
    }
    New-HTMLSection -Invisible {
        New-HTMLTabPanel {
            New-HTMLTab -Name 'PSWriteHTML from File' {
                # as a file
                New-HTMLSection {
                    New-HTMLMarkdown -FilePath "$PSScriptRoot\..\..\readme.md"
                }
            }
            New-HTMLTab -Name 'ADEssentials from File' {
                New-HTMLSection {
                    New-HTMLMarkdown -FilePath "C:\Support\GitHub\ADEssentials\readme.md"
                }
            }
        } -Theme elite
    }

    New-HTMLFooter {
        New-HTMLSection -Invisible {
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Class 'otehr' -Width '50%'
            }
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Width '20%'
            } -AlignContentText right
        }
    }
} -ShowHTML:$true -Online -FilePath $PSScriptRoot\Example-Markdown1.html

r/usefulscripts • • Apr 19 '23

[PowerShell Core] Scrolling-menu navigation.

17 Upvotes

I doubt I'm the first, but I made this to hopefully make SSH easier.

https://www.dropbox.com/s/7ron8yeqsj1i7re/nav.PS1?dl=0

Basically, a bunch of Get-Key If's.
Arrow up/down to scroll up/down, backspace to cd .., c/v to copy/paste, home to Get-PSDrive, pg-up/pg-down to scroll up/down 10, space or ctrl+C to end script in current directory.

Recommend saving in the $home directory.


r/usefulscripts • • Apr 25 '21

[VBSCRIPT][QUESTION] Macro Using Variables in SQL Statement before sending request to SQL Database

17 Upvotes

I'm working with our business ERP which sits on an MSSQL Database. The ERP has a Macro feature built into most modules and uses VBScript to write the Macro. I'm far from being any kind of programmer but being a small company this is a task that has been put on me. Started on Friday and have learned a lot but I keep getting hung up on a certain task I'm trying to complete.

Working within the module that we use to create part numbers I'm trying to create a Macro that uses an SQL Statement to see if the Part ID is referenced in another table. If yes, do nothing, if no, MsgBox (I'd actually eventually like to take it as far as "if no" then go complete a task in another module automatically. But one step at a time).

I have successfully reached out to the SQL database and pulled information in as recordsets. I'm not 100% sure but feel confident that my mistake lies within how I'm trying to define the variable within the SQL statement. The variable being equal to the Part ID that the user is currently viewing.

This thing has gone through at least 100 revisions. For all I know I was closer on the first try than the current version but here's what I currently have:

____________________

Dim TRK

TRK = ID

strCnn = "driver=SQL Server;server=[server];uid=[user];pwd=[user];database=VETEST"

strsql = "SELECT PART_ID FROM TRACE_PROFILE WHERE PART_ID = '" & TRK & "'"

Set rst = CreateObject("ADODB.Recordset")

rst.Open strsql, strCnn

if rst.EOF=true then

MsgBox "Truck Part Trace needs setup!"

End if

rst.Close

____________________

Clarifications:

- Dim TRK is me just trying to create a Dim that can be used within the SQL Statement

- TRK = ID is me trying to define the Dim as the field in the ERP module. In this case "ID" is the Part ID. I'm trying to change the SQL to match the part ID the user is currently viewing.

- if rst.EOF=true... is me trying to get a MsgBox to pop if this part ID does not appear in the other table (this Macro executes when the user clicks save).

- I am currently getting the message pop on every attempt for part ID's that do and do not have records in the other table. This is why I believe the issue is within the variable of the SQL Statement. Seems like the variable is not being recognized and maybe the statement is actually searching the text I have in the statement, which would not exist for any record and result in the MsgBox happening on every save.


r/usefulscripts • • Nov 26 '20

[nirCMD] Changing volume without CMD popping up?

17 Upvotes

I have a macro keypad that allows me to remap keys to open programs. I wanted to change chrome volume so I wrote this and saved it as "volume_up.bat" :

nircmd changeappvolume chrome.exe 0.1

It works well with the volume changing appropriately with every keypress. The only minor issue is that every keypress makes a cmd window pop up for a split second. Is there a different way that I can run this script to prevent that or is it just something inevitable with trying to run something like this?


r/usefulscripts • • Sep 28 '18

[BASH] Jenkins update script

17 Upvotes

Got tired of manually downloading and updating the war file, so I wrote this little script to do it a little easier.

https://gist.github.com/krusem/81af9386cfb29c18abda229aa7cc2c0c


r/usefulscripts • • Aug 13 '18

[PowerShell] Skype for Business Delegated Permissions

Thumbnail
sconstantinou.com
17 Upvotes

r/usefulscripts • • Jun 16 '18

[Request] Looking for a script (or scripts) to automatically update a Google calendar from a CSV every time the CSV is saved (or just regularly)

17 Upvotes

r/usefulscripts • • Apr 20 '18

[request] Need to run powershell script from CD drive. Need to find CD Drive letter or path.

17 Upvotes
**Context**
Building Windows Servers from ISO via Powershell and PowerCli.
Script pulls in a .JSON file with requirements to variables.
Often times there is multiple disks created and initialized via PowerCli.

Update I forgot to mention I am using the Autounattend.xml to call the powershell script. <FirstLogonCommands> <SynchronousCommand wcm:action="add"> <CommandLine>Powershell .\Install\ExtraInstall_Cleanup.ps1</CommandLine> <Order>4</Order> <RequiresUserInput>true</RequiresUserInput> <Description>ExtrasAndCleanup</Description> </SynchronousCommand> </FirstLogonCommands>

After the process is done installing and drives are available.
A Script(Powershell) is run from the CD-Rom drive to install extra cleanup and tweaks.

Example:

    Function VCPP {
     $InstallVCPP = @'
     Set-Location D:\
    $Install = "\install"
    $VCinstall = "\vcinstall\"
    $2008 = "2008\"
    $2010 = "2010\"
    $2012 = "2012\"
    $2013 = "2013\"
    $2015 = "2015\vc_redist."
    $VCRed = "vcredist_x"

  #install Visual C++
   Start-Process -FilePath ( $Install + $VCinstall + $2008 + $VCRed + "86.exe") -ArgumentList "/qb"
   Start-Process -FilePath ( $Install + $VCinstall + $2008 + $VCRed + "64.exe") -ArgumentList "/qb"
   Start-Process -FilePath ( $Install + $VCinstall + $2008 + $VCRed + "86sp1.exe") -ArgumentList "/qb"
   Start-Process -FilePath ( $Install + $VCinstall + $2008 + $VCRed + "64sp1.exe") -ArgumentList "/qb"
   Start-Process -FilePath ( $Install + $VCinstall + $2010 + $VCRed + "86.exe") -ArgumentList "/passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2010 + $VCRed + "64.exe") -ArgumentList "/passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2012 + $VCRed + "86.exe") -ArgumentList "/passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2012 + $VCRed + "64.exe") -ArgumentList "/passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2013 + $VCRed + "64.exe") -ArgumentList "/install /passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2015 + "x64.exe") -ArgumentList "/install /passive /norestart"
   Start-Process -FilePath ( $Install + $VCinstall + $2015 + "x86.exe") -ArgumentList "/install /passive /norestart"
   write-host "Visual C++ sucks" -BackgroundColor Green -ForegroundColor Blue
   '@

    Invoke-VMScript -VM $VM -ScriptText $InstallVCPP -GuestCredential $cred -ScriptType Powershell
    }



I have the Powershell script hard coded to D:\ however I get failures if that drive letter is used for the other variables.
So Sql cluster install requirements need the D:\ to be a datastore for that particular Automated build.
As you can imagine the script will fail. 

Example:
   Function EDrive {
    $Script = @'
   Stop-Service -Name ShellHWDetection
   Get-Disk |
   Where-Object {$_.partitionstyle -eq 'raw'} |
   Initialize-Disk -PartitionStyle MBR -PassThru |
   New-Partition -AssignDriveLetter -UseMaximumSize |
   Format-Volume -FileSystem NTFS -NewFileSystemLabel '--' -Confirm:$false
   Start-Service -Name ShellHWDetection
   Write-Host 'The script completed successfully' -ForegroundColor Green -BackgroundColor Red
   '@

    Invoke-VMScript -VM $VM -ScriptText $script  -GuestCredential $cred -ScriptType Powershell
   }

This goes through a For-each loop for every new VM created.

How do I get the Set-Location to know what the CD-Rom Drive is to run the above script and not error out?

r/usefulscripts • • Oct 09 '17

[REQUEST] SQL Express mail notification

17 Upvotes

Hello, im looking for a mail notification script for SQL Express backup. I know that powershell will be the best, maybe someone have good script for that ?


r/usefulscripts • • Jun 29 '17

Powershell Script for checking Citrix version and then update on clients.

17 Upvotes

The script is semi automated in the way that i have to put in the $citrixnewver= every time a new citrix version comes out. From Citrix version 4.8 that just came out, it now supports auto updating, but not silent. I have reported back from a customer that the script mostly works fine, but also fails to install the newest version on some clients. Any tips and tricks to improve this? My clients are not through a domain but have agents installed on them that make me able to run scheduled PS scripts. They do not have a public server either.

$citrixNewVer = "14.8.0.1010" $citrixver = "0.0" $cdviewer = "C:\Program Files (x86)\Citrix\ICA Client\CDViewer.exe" if (Test-Path $cdviewer) { $citrixver = (Get-Command $cdviewer).FileVersionInfo.FileVersion } if (Compare-Object $citrixNewVer $citrixver) { Invoke-WebRequest -Uri "https://downloadplugins.citrix.com/Windows/CitrixReceiver.exe" -OutFile "C:\Temp\CitrixReceiverWeb.exe" Start-Process -FilePath C:\Temp\CitrixReceiverWeb.exe /silent -wait Start-Process -FilePath 'C:\Program Files (x86)\Citrix\ICA Client\SelfServicePlugin\SelfService.exe' -ArgumentList '-showAppPicker' }


r/usefulscripts • • Jun 19 '17

[request] Check is a process is running, if not, launch an executable

17 Upvotes

I've got a licensing application that wont launch on server startup, someones got to log in to the license server and launch this application.

I want to see if this can be scripted to check if the process is running, I'll have a service account setup to run this script, then launch if it is not running.

Any help is greatly appreciated.

EDIT: the appropriately named Non-Sucking Service Manager was the fix. Thanks everyone!


r/usefulscripts • • Feb 19 '17

[Request] List of all appointments across company in Outlook

17 Upvotes

I received a request from an executive to compile a list in Excel of all meetings taking place in the company. His hypothesis is that there are too many meetings (can't say I disagree).

So I need a script that extracts the name, start date, end date, start time, end time, attendee names, and attendee emails. Can anyone point me in the right direction? All I can find are resources to extract my calendar or shared calendars... I need everyone's calendar data. Thanks!


r/usefulscripts • • Feb 10 '17

[Linux] Sort files based on blank lines(\n\n, not just \n)

17 Upvotes

ASSUMPTION: You know of at least one non-newline character which will not be in the file(s) to be sorted.

ASSUMPTION: Standard Linux tools. My definition of "standard" includes those in RHEL, or more specifically, the (many) production and non-prod servers I have access to, but cannot install anything on. I have a couple of log files that run simultaneously. Occasionally these will have java stack traces in them, i.e. multiple consecutive lines. While I can combine the files into one larger file, they will be out of order. I want to sort them based on the first line, then subsequent lines. The reason for this is that the first line has a date/timestamp in it as one of the first things it does.

I don't know what characters will be in the log file, so I used a control character(0x1d, group separator) to change every newline character into; this makes one super-long line, change all the repeat sequences of the control character to a newline, sort now(since it's just a bunch of lines with some control characters), then change the remaining control characters back to newline characters.

Script:

cat file | tr '\n' ' ' | sed 's/ / \n/g' | sort | tr ' ' '\n'

Sample log entry:

[2017-02-10 08:45:30.123] foo bar baz
  java stack trace. Error message here
    at com.myorg.file(file.java:1234)
    at com.otherorg.theirs(func.java:2345)

r/usefulscripts • • Feb 01 '17

[REQUEST] Monitor memory usage (per process) and email me when a proc's memory usage is above a threshold

17 Upvotes

I'm afraid my bash skills are a little too pathetic to cobble this together from StackOverflow answers. I just want an alarm whenever some proc uses more than 80% of the available memory.

I guess it doesn't have to be a bash script, though, does it?


r/usefulscripts • • Aug 09 '16

[POWERSHELL] Connect to an EC2 instance without knowing the password

17 Upvotes

Hi,

I wrote this script based off of one my colleague's Jason Brown (@cloudyopspoet) initial script while working at Domain Group in Sydney. You will also need @jappbrasser's Connect-Mstsc function from https://gallery.technet.microsoft.com/scriptcenter/Connect-Mstsc-Open-RDP-2064b10b (I converted it to a module and import it in my profile). It allows you to connect to an EC2 isntance via RDP using only the powershell commandline and the pem file used to encrypt the local admin's password. You never need to log on to the console to decrypt the credentials, you only need the instance id.

Script is available from github - https://github.com/kirkbrady/tools

Features of the script -

  • allows you to pass in values from the pipeline. so you can use get-ec2instance with a filter and as long as you have an instance id at the end, it will try and connect.

  • you can pass an array in through the pipeline, and connect to multiple instances at once.

  • supports non standard local adminstraor usernames (although default is still Administrator).

  • allows setting of pem paths and custom pem files if the value it gets from the instance properties has changed - eg filename change for whatever reason.

It does require you to have your powershell environment already set up however, with all the AWS defaults configured.

Please try it out and let me know what you think!


r/usefulscripts • • Aug 08 '16

[POWERSHELL] Using the Project HoneyPot API with Powershell

17 Upvotes

I wrote a function to integrate powershell with the Project Honey Pot API. I'll admit it has a limited use, though I have been using it as part of auditing types of IPs that are hitting my logs.

My blog write up on using the api

PasteBin of just the function

My github with the function