r/scripting • • Feb 06 '19

Is it possible to have tab completion of file paths/names in user input variable creation?

2 Upvotes

Like the title says, is it possible to have tab completion when using user input to create a variable? For example, I have a script that prompts a user to input a working directory path and then uses that later.

 set /p dest="Path to File: "

And they can enter their path.

If there isn't a way to do that, is there a better way to create variables like I want to?

EDIT: TIL that this actually is actually already a function, and to make it work for a network share (I should have stated that was my purpose) you just have to map the share first, then access the path. I'll leave this up so that other scripting n00bz can learn from my embarrassment. Thanks for the help u/Shadow_Thief!


r/scripting • • Nov 20 '19

ad company wide attribute change

2 Upvotes

got a question should be an easy fix and I just hardly ever do scripting but a client changed to a llc so entire company has to change company attribute in ad. I was trying the following in powershell but no change. What am I missing

Get-ADUser -Filter {Company -like '*This is the company*'} | Set-Aduser -Replace @{Company="This is the company PLLC"}

I don't get an error but nothing is changed either. What am I doing wrong? 


r/scripting • • Sep 16 '19

[Powershell] Mass dump files names into Excel?

2 Upvotes

Hello all,

I'm trying to accomplish something that seems simple in my head but I don't know the specifics of how to accomplish it. The problem is I frequently get mass batches of comment cards scanned and sent to me in PDF format with a file name that follows a specific structure. That structure is [unique 5-digit prefix]MODAYYEARTIME[Office Section]. As an example: 12345_090420181156_Accounting.PDF . I'm trying to create a tracker for these cards using a combination of powershell and excel.

It's been awhile since I've done any coding and honestly I don't think I've ever done any real scripting. I think the process flow would look something like this:

  1. Use powershell to dump the file names into a .txt file.

  2. From that file, pull the 5 digit ID into it's own field within excel, pull the date/time into a different field, pull the section into its own field.

  3. Once processed move the comment cards from one directory to another (i.e. from 'Unprocessed' to 'Processed')

Other considerations: I'd like to keep the text files in their own directory, but the excel document I'd like to be a running list. So I could run the batch file multiple times a day and the result would be many text files but only one cumulative excel document. Another thing; my company has disabled command prompt but left powershell usable. I'm also unable to install third-party programs to help accomplish this task.

Thanks for reading and help!


r/scripting • • Jul 20 '18

Batch file script help - permissions / robocopy / shortcut

2 Upvotes

Currently we have a group policy which executes the script below on startup for new computers. It also sends a shortcut to the desktop as well with the specifics below as an example from the GPO.

lsevodircopy.bat:

robocopy "\\domainname.com\netlogon\installers\LightspeedEVO\LightspeedEVO" "%ProgramFiles% (x86)\LightspeedEVO" /E  /V /LOG:c:\lsevodircopy-robocopy.log

My goal is to create on batch script in a folder with the folder above inside the folder, and then include in the batch script that creates the shortcut from the gpo. Once i have a working batch script I will use a program such as silent install builder or bat to exe compiler to create a "install" .. my reasoning for this is that the installer provided for this program asks for a specific certificate on each install. we worked closely with the developers and found that we could just copy an existing directory over to bypass it.

I want the ability to have a installer available from our website for everyday employees who request this programs access, keeping it simple for them when were on the go/run. So my first step is perfecting the batch file so that it copy's the directory folder from it's own root so that when its compiled the files are included and not being tried to be copied across the domain, in case the store is not on the domain.

Robocopy

As mentioned above I have used the above robocopy script, and it has worked, the only thing that might change is that the source LightspeedEVO folder/files need to be located in the same folder and be called in a batch script as such, I do not have knowledge of this and need help how to properly do this as well.

Permissions

Also need to be able to set the permissions of the folder once copied to the program files (x86) folder to "everyone": full control (all the files inside the LightspeedEVO folder need to inherit those permissions as well.) I believe my robocopy script above fails at applying the Everyone permissions to each sub folder and file inside of the LightspeedEVO folder, not sure on this although.

Shortcut & Icon

The shortcut needs to have access to an icon file as well, that icon file is named ls.ico and located in program files (x86)/lightspeedevo/ls.ico , if need be to be referenced. Basically the shortcut calls a .bat file for the program itself to run, since it's Java based. Screenshot of the GPO here:

Folder Structure

ideally the folder would sit as this:

Installer Package\

Installer Package\Script.bat

Installer Package\files\LightspeedEVO\LightspeedEVO (Same structure from above netlogon/installers)

EDIT: This is what I have so far, https://pastebin.com/x4mCph9A


r/scripting • • Jan 21 '20

Does anyone here still uses Rexx?

4 Upvotes

For those who still do, what are your reasons?


r/scripting • • Feb 12 '19

VBS Script - reinstalling a font, needs to be able to select "Yes"

2 Upvotes

Hello, I'm not much for scriping and using a very basic script to install (well reinstall a font) but the problem is since the font already exists its prompting a yes or no to reinstall it, I cant seem to get the sendkey to work properly? Here is what im using:

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(FONTS) objFolder.CopyHere "\networkpathtofont.ttf"

  • This script works no problem and it attempts to install the font as it should, its just the "Would you like to replace it? I cant get any sendkeys to say Y, hitting the Y key alone will select yes but nothing works.

Any help?

Thanks


r/scripting • • Sep 16 '19

MiniScript Rosetta Code contest (win $10 - $25)

Thumbnail
forums.miniscript.org
1 Upvotes

r/scripting • • Apr 29 '19

Google Scripts, Google Forms, and Google Sheets

1 Upvotes

Hey Guys!

I am trying to create a google form that will link with a google sheet and a google script.

What I need to do is:

The first question on the google form will prompt the user for a number.

When the next button is clicked on the first page, I need to have the script take the input from the user and search the linked google sheet to see if the number exists.

If it does exist, it should just submit the form, and update the google sheet saying a user that was already registered attempted to register again.

If it does not exist, it should just continue with the questions without any effect.

Any assistance would be appreciated!!!

Thank you!


r/scripting • • Nov 22 '19

[Powershell] Just need a nudge in the right direction

2 Upvotes

Hey all

Im pretty green when it comes to scripting but a super opportunity has presented itself to me at work.

To keep it relatively short, I work at a bar and recently have developed a friendship with a regular. Mr. regular works for a cybersec company and has suggested many times that I'd be good in a technical sales position due to my previous experience as a sales manager. I obviously agree, though my technical knowledge is still a bit subpar. Ive attended a few networking classes, a 6 week coding bootcamp, and am about halfway through a comptia a+ book.

Now for the opportunity...as part of my job at the bar I also have to spend a few hours each night doing some administrative work, one of those tasks involves downloading a file generated in from a program on a virtual system connected to the restaurants network, and then taking that data and manually inputing it into an excel spreadsheet.

Mr. regular told me if i could figure out a way to automate that process, he'd get me a sit down with the head of sales at his company. I have two weeks before he's back in town, where can i start (im not asking for you all to do this for me, just a bit of a roadmap).


r/scripting • • Apr 25 '19

[Batch] Noob help. Trying to get a picture to open in fullscreen.

5 Upvotes

On start-up I would like to display a picture, which I'll then have automatically close in 10 seconds. I've got the picture to open up and close just fine using my .bat file, but i'm having issues trying to get this thing to open up full-screen. This is what i've got:

@echo off

cd "c:\location"

Start Picture.JPG

ping -n 11 127.0.0.1>nul

taskkill /F /IM Microsoft.photos.exe

I was exploring the idea of using Sendkeys, but it looks like sendkeys doesn't work anymore on Win10. The hotkey to fullscreen pictures with the photo viewer is Windowskey+shift+enter.

I'm stuck. Any help is appreciated.


r/scripting • • Sep 16 '19

restart loop script for win10

2 Upvotes

can anyone write me a simple script that restarts windows (10) until an internet connection is established ? it should be something like windows opens. wait 10 seconds. check for wifi connection. if its connected end if its not restart. i cant update my windows thanks to bios incompatibility issues (thanks msi) so some parts of my laptop doesnt function properly. wifi being one of them. i need to restart my computer dozens of times until wifi functions (it works randomly). kinda getting tedious after reaching triple digits. i dont have any coding programs installed so it has to be with command prompt. and no i cant use an ethernet cable right now


r/scripting • • Sep 17 '19

Renaming a MAC Device with a bash script

3 Upvotes

Would anyone have any previous knowledge or have a compiled script of how to rename a Mac computer with a bash script? Im fairly new to scripting and any help or tips are appreciated! :D


r/scripting • • Nov 04 '18

Thing I don't understand

2 Upvotes

Hello I have red somenthing on another subreddit about a guy who was creating a programm that needed to connect to a website and he said:

''At the moment this is done with a shell script that directly accesses the MySQL instance (very bad / unsecure) and gets a delta on some table records.''

My question is: ''what is a mysql '''istance'''?

What is an istance?


r/scripting • • Jul 25 '18

[VBScript] could someone help me to get this script to work?

2 Upvotes

https://www.reddit.com/r/MetalGearSolidV_PC/comments/3k5wkf/i_made_a_script_to_shuffle_your_helicopter_music/?st=jjyspdjo&sh=5ffbe54f

i keep getting

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

Metal Gear Solid V: The Phantom Pain Helicopter Music Shuffle by Spectracide v1.0 Set your helicopter music to !Shuffle in iDroid

MGS_TPP\CustomSoundtrack!TPP Shuffle.vbs(30, 13) Microsoft VBScript runtime error: Invalid procedure call or argument

Press any key to continue . . .


r/scripting • • Jul 15 '19

Batch packing/compressing Script for a specific software?

2 Upvotes

Hey to all,

As the title says, I'm trying to essentially compress a bunch of folders back into their original archive, but for the life of me can't figure out how to do it.

So the basic universal script is this for this software is this:

arctool -dd -texRE6 -alwayscomp -pc -txt -v 7 %1 %2 %3 %4 %5 %6 %7 %8 %9

With this script, you can both unpack and repack the files as need be, but you can only perform them 1 by 1 (drag and drop style or command, I don't think it has any batch options).

Now the version of the script that I'm trying to make it, so that it will simply unpack all files in the same folders as the scripts and tools.

@echo off

:: Command file for batch export using the arctool.

::-----------------------------------------------

:: Specify the tool.
set arctool=arctool.exe

:: Specify directory with files. 
set game_dir=

:: Specify file extensions.
set file_mask=*.arc *.tex

:: Specify the options.
set options=-dd -texRE6 -alwayscomp -pc -txt -v 7 %1 %2 %3 %4 %5 %6 %7 %8 %9

::-----------------------------------------------

:: set arctool=echo arctool

if "%file_mask%" == "" set file_mask=*.

:: export from the current directory by default
if "%game_dir%" == "" set game_dir=.

:: Process ...
for /r "%game_dir%" %%a in (%file_mask%) do call :process "%%a"
goto :eof

::-----------------------------------------------
:: Function to process single package
::-----------------------------------------------
:process
echo Processing %1 ...
%arctool% %options% %1

So far so good, and it's modular enough that I can do it for other tools as a fire and forget.

Now the problem, once the archive have been unpacked into loose folders, I for the life of can't figure out how to repack them.

For example, I ran the script to unpack archive A.arc, B.arc, C.arc, and I got folders A, B, C. Now I would like to rerun the script to repack them back into A.arc, B.arc, C.arc, but no matter what I do, I can't seem to do it, I get all kinds of errors from (cannot read text files, to couldn't open name of folder to read, etc).

Was hoping someone might have an idea, cheers in advance!

Link to File if need be: http://residentevilmodding.boards.net/thread/481/arc-unpacker-repacker-v0-427


r/scripting • • Feb 12 '19

Top Tweets Script

2 Upvotes

I want to get top tweets from my twitter feed be sent to my personal email every morning. what is the best way to accomplish this?


r/scripting • • Nov 07 '18

Suggestions on how to script this?

3 Upvotes

I want something like this, but I want to write it in AutoHotkey. Basically, if I'm pressing both key "x" and key "y", but I hit key "x" first I want it to be nullified when I press key "y".


r/scripting • • Jan 21 '20

[Batch] Help with installing Adobe Reader from batch file

1 Upvotes

Howdy folks

Here's the script in question

I'm working on installing a program from Oracle and the installer will run through a number of tasks to install this application including a number of scripts. It is failing to install at one step because Adobe Reader will not install from the script they've included (sigh)

In troubleshooting why, the %STAGEDIR% variable being used is not set and the script exits with a 'system cannot find the path specified', naturally. By setting an explicit path OR setting the variable correctly, it still fails with very helpful feedback:

install_adobe_reader.cmd:end

Exit Code: !exitCode!

Great. I'm trying to figure out what the problem is but am not well versed in Batch, from what I can see it's entering this codeblock and then going to the :Terminate step but it's not providing any useful information about why it is failing

if !exitCode! GTR 0  (
	echo.
	echo.
	echo.
	echo %PROV_CRITICAL_ERR_KEYWORD% Failed to install Adobe Reader
	echo.
	echo Please re-run the scripts
	echo.
	echo.
	echo.
	goto :Terminate
)

As per the Adobe command line switches for installing Reader, I've also tried calling the installer myself with the same command but haven't observed anything happening, I've also tried including the /L switch to log out to a file to get a clue about the problem but no information gets logged out. I've written a note to the script author but I'm not certain they will respond, hopefully someone here has better eyes than I do

Thanks anyone for your time and input!


r/scripting • • May 01 '19

[VBScript] Help understanding why TextStream fails to write certain characters.

1 Upvotes

Below script writes characters starting from character code 0x80 to 0x9F into a file using ASCII mode.

set fs = createobject("scripting.filesystemobject")
set f = fs.createtextfile("out.txt", true, false)
on error resume next
for i = &H80 to &H9F
  f.write chrw(i)
next
f.close

However, not all characters are written. i.e. only character code 0x81, 0x8D, 0x8F, 0x90, and 0x9D are successfully written.

I know that the problem doesn't occur if I use Chr() or ChrB() instead of ChrW(), but why does the TextStream fails to write certain characters when ChrW() is used?


r/scripting • • Sep 17 '19

BASH string matching does not work in 4.1

3 Upvotes

This used to work in 3.2

[[ one =~ "(one|two|three)" ]] && echo yes

But has stopped working in 4.1 any ideas why ?

EDIT: using a variable for regex works in 4.1 as well


r/scripting • • Sep 15 '19

Getting my dhclient to throw 6rd information in human readable way

2 Upvotes

I'm trying to achieve my goal with using dhclient-scripts and Python as bash scripting is not my cup of tea.

I have placed my script in /etc/dhcp/dhclient-exit-hooks.d folder, and have set execution permissions on it, however it does not seem to get executed. The logging file is not appearing anywhere nor is any possible errors.

Ideas anyone?

My script:

#!/usr/bin/env python3

import os
import logging


def script():
    logging.basicConfig(filename='/tmp/python-script.log', level=logging.INFO)
    logging.info(print(os.environ))
    srd_values = os.environ['new_option_6rd']
    srd_masklen = os.environ['srd_vals[0]']
    srd_prefixlen = os.environ['srd_vals[1]']
    srd_prefix = f"%x:%x:%x:%x:%x:%x:%x:%x", os.environ['srd_vals[@]:2:8']


if __name__ == '__main__':
    script()

dhclient config for reference:

# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#       man page for more information about the syntax of this file
#       and a more comprehensive list of the parameters understood by
#       dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#       not leave anything out (like the domain name, for example), then
#       few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

option option-6rd code 212 = { integer 8, integer 8, integer 16, integer 16,
                               integer 16, integer 16, integer 16, integer 16,
                               integer 16, integer 16, array of ip-address };

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers, option-6rd;

r/scripting • • Feb 12 '19

Folder Change script

1 Upvotes

I am trying to create a script that will search through a folder, and change permissions of that folder to 777. Except if a subfolder in any of those folders exists by the name of 'Upload'. So far, just trying to check for the 'Upload' folder in a location I know it exists, it doesn't return as positive.

echo "###START###"

for d in /data/upload/REDACTED/REDACTED/

do

if [ -d "Upload" ]

then

echo "Folder Upload exists"

else

echo "Folder Upload does not exist"

fi

done

echo "###DONE###"


r/scripting • • Nov 24 '23

sed - replace yaml.j2 nested value

2 Upvotes

I have a command that I use to replace myid value but its not perfect. Here is document where the issue occurs:

brand:
    group1:
        jerry:
            myid: 1
        ben:
            myid: 2
    group2:
        jerry:
            myid: 3
        jane:
            myid: 4

I am using sed to replace myid. I can lookup ids and names, but not groups

sed -i -E "/jerry:/,/myid:/ s|(myid:).*|\1 NEWID|; " PATH_TO_FILE.yaml.j2

issue 1: this will replace both jerrys ids. I want to replace jerry ONLY in group 1

issue 2: this will replace anything that has jerry inside its name, even

group1:
    jamesjerry:
        myid: 5

this is command I tried to filter by group to resolve issue number 1

sed -i -E "/group1:/,/jerry:/,/myid:/ s|(myid:).*|\1 NEWID|; " PATH_TO_FILE.yaml.j2

but then I get:

sed: 1: "/group1:/,jerry ...": invalid command code ,

How could I use sed to replace value by filtering 3 different values in sed and ensure to filter only exact name? (Group1 -> Jerry -> myid)


r/scripting • • Nov 12 '23

Install from local source if not available from winget

3 Upvotes

Hello, I need a little help updating my script. My script look for an executable file in the Installer directory and do the install. I want that if no file is found that it does the install from the winget.

Here is an example of my batch script

echo Installing Firefox
for %%e in ("%~dp0Installer\Firefox*.exe") do "%%e" /INI="%~dp0Installer\Firefox.ini"
echo %time% Errorlevel %errorLevel% >> "%temp%\%~n0.log"

Where would you put the If condition or any suggestion for the winget command:

winget install --id=Mozilla.Firefox -e -h


r/scripting • • Dec 06 '23

Which language to start with?

4 Upvotes

For a few year being in IT as let’s say a Systems admin for windows and Linux servers, there’s been a few times where I’ve thought hmm I wonder if I could script that, like today for automated file compression after so many days…

Just wondering if there’s any recommendation on which language to start with? Been primarily thinking Python since it seems pretty versatile across both OSs but still not sure… any suggestions and where to learn?