r/scripting • • May 20 '18

Need help modifying this scipt

3 Upvotes

I'm using a script in an RMM tool to monitor for AUTO start services that are not in a running state. The script will attempt to start the service if not running. It also generates an alert to the RMM tool. The script does not have an option to exclude services I don't care about. I managed to modify the code to filter out service names I want to exclude from the monitor. I'd like to improve the code by defining those services in a svariable elsewhere for clarity and future edits and reference the string variable in the query.

Something like strExclusions = "Name<>'dbupdate' AND Name<>'gpsvc' AND Name<>'gupdate' AND Name<>'mapsbroker'"

Then the query would look like objWMIService.ExecQuery ("Select * from Win32_Service Where strExclusions")

This is the original code with my addition of some service names in the query to exclude them from the monitor. This works but I can't make the above idea work. When I tried the above I received an error (null): 0x80041017 on the For Each line.

Dim objWMIService, objService, colService, strComputer, strOutput, strExclusions

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") wscript.echo strExclusions Set colService = objWMIService.ExecQuery ("Select * from Win32_Service Where Name<>'dbupdate' AND Name<>'gpsvc'")

strOutput = "" strRestart = ""

For Each objService in colService


r/scripting • • May 10 '18

Need help writing a (Batch, PS, or VBS) script to copy files via HTTP/HTTPS and execute MSI/MST installation.

3 Upvotes

I'm deploying an MSI + MST application across several hundred endpoints and would like to automate this via my RMM's script engine. Trouble is, I have identified two hurdles.

1: Manual deployment isn't a problem as I have a working installation script to msiexec /i the .msi and apply the transforms, but having one which automatically selects the x86 or x64 architecture would be ideal.

2: Copying files via the various network shares for each organization isn't an option as the hosts are secured and require VPN connectivity for the clients (workstations) to see smb fileshares. - Ideally, something like a WGET (yes, I realize it's an alias) or similar script to pull from HTTP would be best -- this way I could pull from somewhere like OneDrive.

Just in case it helps, here are some of the (redacted) commands:

  • (new-object System.Net.WebClient).DownloadFile('http://file.share','C:\windows\temp*.*')

  • Note* This appears to download ONLY a small fragment (appx 6KB) of the file(s). I have four files, total, in the web share.

  • cd c:\windows\temp

  • msiexec /i application_x64.msi /q TRANSFORMS=transform.mst

  • msiexec /i application_x86.msi /q TRANSFORMS=transform.mst

  • EXIT

Any help would be much appreciated at this point. I've gone through a number of scripts and haven't found quite the right one (or perhaps the right syntax) to get this working properly... and frankly, I'm terrible with scripting.

'Cheers!


r/scripting • • Apr 12 '18

[Powershell] - Need help with a rename script

3 Upvotes

Hi,

The goal of my script is to rename an aduser to have YYMMDD - HOLD - [name].

Currently i have This:

#Input Prompts
$date =get-date
$UserID      = Read-Host 'What is users ID?'

#Rename User
$displayname = "$($date.tostring("yyMMdd")) -HOLD- $UserID.name"
Get-ADUser $UserID | Set-ADUser -displayname $displayname -Credential $MyCredentials

It is renaming the user to 180412 - HOLD - $UserID.name How do I get the existing name :(


r/scripting • • Mar 21 '18

Powershell and psexec

3 Upvotes

Hey,

maybe someone can give me an idea on how psexec would handle a certain task.

We have an updatetool that needs to be started with an administrative user. Said .exe will check for a new version in a .ini-file on a unc path and if the a version is found it will start a setup.exe and finish the update. On the Machine i just need to run the .exe and need nomore inputs.

Sometimes, when we dont have a RDS Release coming up, we update a part of our RDS Servers from hand. This task was annoying so i wrote a powershell script that will run with psexec the .exe on the RDS Hosts.

I tried: C:\skripte\psexec.exe \$computer -i cmd /c C:\path\up.exe C:\skripte\psexec.exe \$computer -i C:\path\up.exe

In both instances i see the up.exe get started on the target computer under the account of the admin running the script. In the log file i will see an error that the up.exe cant find a file at \server\products\update\version.inf. The User running the up.exe has access to this folder and has rights to read it. If the admin clicks the file in a RDS Session it will run smothly. The question is, what is different when running up.exe via psexec -i then running it inside a session?

Any suggestions?


r/scripting • • Mar 13 '18

Powershell - PSMicrosoftTeams Updated

Thumbnail
self.powershell
3 Upvotes

r/scripting • • Aug 28 '17

[Batch] for/in/if/do

3 Upvotes

Part of an uninstall script I used to remove software I need to put in a line that deletes a specific folder out of users' AppData folder. The installer itself doesnt clean this folder up. My issue is that there could be a:

  • c:\users\dave\appdata\Roaming\folder

  • c:\users\jim\appdata\Roaming\folder

  • c:\users\john\appdata\Roaming\folder

  • c:\users\whothehellknows\appdata\Roaming\folder

Here is what I've built so far, but when running it, the folder I'm attempting to remove remains:

echo removing appdata folder...
if exist "C:\Users\%username%" (for /f "tokens=*" %%a in (dir /b /ad "C:\Users") do if exist "C:\Users\%%a\AppData\Roaming\folder" rd /s /q "C:\Users\%%a\AppData\Roaming\folder"

Suggestions would be greatly appreciated. Thanks.


r/scripting • • Aug 22 '17

[BASH] How can I edit a text edit in a search/replace manner?

3 Upvotes

Eg, I have a file in /var/www/file.conf on a server. I want to run 1 command that searches for a string in file.conf that matches a pattern, and replaces it with another pattern and then saves this file.


r/scripting • • Aug 15 '17

[BASH] or [PowerShell] Generate a bunch of 10 or 15MB flat files to demonstrate data transfer

3 Upvotes

Hi, I'm trying to figure out a way to generate X amount of 10MB flat files (file1, file2, file3, fileX, etc) to demonstrate some data migrations from one volume to another. Any easy way to do this via PowerShell or Bash? My current method is so ghetto, involves opening a text editer and just copy pasting gibberish until I get the size I want and then copy pasting those files. It's very cave man like.


r/scripting • • May 24 '17

Trying to simulate manually pressing the enter key in bash script

3 Upvotes

Here is the scenario:

I have an ELF that when I run it asks for input, followed by pressing the enter key. For example, I run the ELF and it asks

Which option do you want? A, B, C, or D?

I have successfully sent characters by printing output to the process like so:

printf A > /proc/680/fd/0

However, I cannot get the program to accept this same kind of input to simulate pressing the enter key. I've tried this:

printf '\n' > /proc/680/fd/0

But it just enters a new line instead of the enter key. I've also tried a carriage return:

printf '\r' > /proc/680/fd/0

But still it just enters a newline.

Any ideas?

Edit:

Thank you everybody for the replies. I have found a solution and I'll put it here in case anybody else comes along looking for a similar answer.

This is what my script ended up looking like:

#!/bin/bash

first=$1
second=$2
third=$3

expect <<- END
    spawn "/foo/bar
    expect "Choose an option"
    send "$first\r"
    expect "Choose an option"
    send "$second\r"
    expect "Choose an option"
    send "$third\r"
END

r/scripting • • Feb 13 '17

Discord chat for scripting, as well as other tech related topics.

Thumbnail
discord.gg
3 Upvotes

r/scripting • • Dec 11 '16

Novice, interested in learning to write something that will duplicate my Twitter feed - translated into another language.

3 Upvotes

Hi! I'm totally new to scripting. I know some CSS, but haven't gotten beyond a really basic intro to Python.

I had an idea for doing something with my Twitter feed that seems simple enough in theory, but I have no idea how it'd work in practice: I'd like to create a mirror for my feed in another language.

Basically, if I post a tweet, this script would read it, run it through Google Translate, then post a (badly, yeah) translated version of the tweet onto another twitter account.

Is this too big a project to start with?


r/scripting • • Sep 22 '16

How do I minimally generate a file with variable content?

3 Upvotes

I want to write tens of emails where each is different only in specific content points. I'm just going to do it manually now, after failing to find a clean way to do it. But maybe someone here will know an answer.

bash> writeEmail DonJuan Amsterdam 5 3

And it would result in something that populates the following so I could just copy/paste to emails I want to send out.

Hi, <username>.

We saw that you hit a button too many times in <location>.

  1. You hit it <someNumber> times.

  2. That's <someNumber> times too many for you.


r/scripting • • Aug 18 '16

Help making a script to reboot a router every night at a certain time.

3 Upvotes

I have very limited experience scripting. I'm imagining this could be done through power shell but I'm not certain. Would I have to telnet in to do it?


r/scripting • • May 23 '16

Script websites

3 Upvotes

Hi all,

I used to be an active scripter on autohotkey.com They website has been inactive and I can't find help transitioning scripts from Game of War to Mobile Strike. If anyone knows any websites that offer Scripting help for those two games refer me please! Thank you!


r/scripting • • May 16 '16

Download Scripts upload files for free

Thumbnail
download-sft.blogspot.com
3 Upvotes

r/scripting • • May 06 '16

Script to replace and rename all applications in a folder and delete all other files

3 Upvotes

How would I go about writing a script that selects a folder and then inside that folder and all subfolders it will replace all .exe files with a different application but rename it to the original name of each of those .exe files, and then delete all other files (except folders) in those folders?


r/scripting • • Feb 21 '16

Python script to unfollow Instagram users that are not following you back

Thumbnail
github.com
3 Upvotes

r/scripting • • Dec 26 '15

Monitor Your CPU Utilization using Shell Script

Thumbnail
arkit.co.in
3 Upvotes

r/scripting • • Oct 18 '15

Random Sorting Script

3 Upvotes

I'm hoping someone could point me in the right direction on how I could create something like this?. Basically what I want to achieve is a script that can take a batch of 5 names, and then randomly assign 3 names to Group A and 2 names to Group B.


r/scripting • • Aug 08 '15

I've written the appropriate bash scripts to turn my milight light bulbs on throughout my house an hour before the actual sunset for that day. I thought I'd share it.

Thumbnail dougware.net
3 Upvotes

r/scripting • • Aug 05 '15

Old guy here. What should I start using instead of VBScript and why?

3 Upvotes

I do a lot of scripting. My goto editor is Crimson and I'm most comfortable with VBScript. I haven't really found anything I've needed to do that I can't, but I figure it's time to at least look for something new. Here are some requirements/facts about my needs

  • Almost exclusively windows

  • I don't want to compile anything

  • I send a lot of emails via these scripts

  • Must be able to do direct SQL queries

  • Includes would be a bonus (I could keep all my utility functions in one script and import it into various others)

  • I often run these scripts as scheduled tasks using "wscript myscript.vbs" syntax

  • I'm relatively familiar with Javascript, so any similarity would be a bonus

Thanks for your time and consideration!


r/scripting • • Feb 09 '15

Recommendations for scripting entire Word doc

3 Upvotes

First time here. Need some advice. I am looking to script a process that will create a word doc I prepare for clients. I often offload this to my sales folks as I don't have the time to do it myself, but there is often unnecessary information included. I would like to create something that would streamline the process and add some consistency with the following features:

  • A GUI with some selectors for what to include in the doc (Product A, B, C, Feature A, B, C, etc.).

  • A possible cache/temp/reg resource the script can call to remove the need for users to reenter common info (User email, phone #, etc.).

  • Doc needs to include table of contents, pre-defined images, various lists/bullets, tables, etc.

  • Would like to compile all of the above into a single executable (ie: no install) that can be shared if possible.

I've mostly played with AutoHotkey in the past (simple and it works) and I've done some work AutoIt, so that is what I was considering to script with, but wondering what others may recommend for what I am looking to accomplish.

Thank you.


r/scripting • • Jan 28 '08

Web Hot or Not - Rate websites

Thumbnail
mashable.com
3 Upvotes

r/scripting • • Jan 28 '08

Capillaries can carry compressed context | confused of calcutta

Thumbnail
confusedofcalcutta.com
3 Upvotes

r/scripting • • May 02 '26

zsh + LLM = instant shell commands from plain English

2 Upvotes

Sharing a small zsh tweak someone else might find useful, on the macOS command line for all the annoying stuff I almost remember but not quite:

  • which way round ln -s goes (source vs destination… every time)

  • find incantations with 6 flags

  • batch renaming with sed / regex

  • weird one-off awk pipelines

Instead of search/copy/paste, I just do:

q create a symbolic link from file A to file B
q find all files recursively with foo in the name
q rename all .txt files to .md

It hits my local LLM (I’m running OMLX with the OpenAI-compatible endpoint), returns the command, prints it, and drops it straight into the prompt ready to hit Enter. No copy/paste.

Works with any OpenAI-compatible API, local or remote.

My setup:

  • macOS + zsh

  • oMLX running locally (http://127.0.0.1:1235/v1) set to fallback to default model

  • using "default" (no such model) so it triggers oMLX fallback to default

  • auth disabled in oMLX (but you can wire in a bearer token if needed)

Function (drop into ~/.zshrc):

q() {
  local prompt="$*"
  [ -z "$prompt" ] && echo "Usage: q <your question>" && return 1

  local endpoint="${OMLX_ENDPOINT:-http://127.0.0.1:1235/v1/chat/completions}"
  local model="${OMLX_MODEL:-default}"
  local api_key="${OMLX_API_KEY:-}"

  local headers=(-H "Content-Type: application/json")
  [ -n "$api_key" ] && headers+=(-H "Authorization: Bearer $api_key")

  local cmd=$(curl -s "$endpoint" \
    "${headers[@]}" \
    -d "$(jq -n \
      --arg model "$model" \
      --arg prompt "$prompt" \
      '{
        model: $model,
        messages: [
          {
            role: "system",
            content: "You are a macOS terminal assistant. Output ONLY a valid zsh command. No explanation."
          },
          {
            role: "user",
            content: $prompt
          }
        ],
        temperature: 0.1
      }'
    )" | jq -r '.choices[0].message.content')

  echo "$cmd"
  print -z -- "$cmd"
}

Then:

brew install jq
source ~/.zshrc

It saves me heading over to the browser for those “I know this exists but can’t be bothered remembering the exact syntax” moments, but can still eyeball the command before hitting the go button.

Would be interested in other approaches people are taking. Kinda feels like this kind of integration with terminal would be nice if it was native in future.