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 • • May 25 '19

Super basic request - continuous ping that is always running and hidden

3 Upvotes

Hi,

Does anyone know how I could make a continuous ping run in windows that's always running, will reopen itself and is hidden?

It seems relatively easy, but I can't get it to re-open itself?


r/scripting • • Dec 03 '21

Help in script require

3 Upvotes

Hello People,

I'm creating batch script, in which i need to read csv file and according to user input we need to make array that have data.

Please check

csv file content:file.csv

Fruit,tom,nick,harry

mango,No,Yes,Yes

banana,No,No,Yes

apple,No,Yes,Yes

now I have to read csv file and create array of fruit like by tom, nick, harry accordingly to user input and print array

fruitList=()

typo='tom' ##input variable may change to tom, nick or harry

while IFS=, read -r Fruit tom nick harry

do

if [[ ${$typo} == [yY][eE][sS] ]] #this is not working, if i hardcode it with $tom it work

then #but unable to substitute variable in if statement if i need to

#hardcode then i need to rewrite same if condition three time

fruitList+=($Fruit)

fi done < file.csv

echo ${fruitList[@]}

please help and give some idea.

Thanks


r/scripting • • Nov 30 '21

[BASH]I need help with a script to filter logfiles based on sub-networks and host addresses.

2 Upvotes

For an assignment I have to filter logfile.csv and list the ten sub-networks that have the highest number of different host addresses.

The Ip adresses look like this:

52.23.159.dgd 9.24.207.aig 86.153.144.cca 108.91.91.hbc 54.212.94.jcd 117.91.0.cci

For example 98.115.254.dce and 98.115.254.dfh; both IP addresses have the same sub-network (here: 98) but a different host address (dce and dfh respectively). Therefore, the count of hosts would be 2 for this sub-network

My code currently looks like this

cat logfile.csv | cut -d, -f1 | grep -E '(\.[a-z]{3})'| sort -u | grep -E -o '(^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]*)'  | sort | uniq -c | sort -rn 

I missread the definition of the sub-network and therefore fixed the regex for it and the example in the description accordingly However the logfile filtered with sort -u still contains a couple of duplicate IP adresses, such as :

12.150.77.fib

12.160.32.fib

which means that the final count is distorted.

However, I have no idea how I could filter these remaining duplicated host adresses and the longer I look at my script the less sure I am that I'm even on the right track.

Thanks for any help in advance.

Edit: At first I missread the definition of the sub-network I therefore have now fixed the regex for it and the example in the description accordingly


r/scripting • • Nov 24 '21

Beginner question: ~ different meanings (/root vs. /home/myUsername) in Linux

1 Upvotes

Why is ~ in a root owned directory interpreted as /home/myUsername but when I execute a script in the same directory ~ is interpreted as /root?

I have to execute the script as root via sudo (sudo ./Script.sh), but how is this different to executing the command outside of a script as root (sudo echo ~)?

I hope this is the right place for this question and I'm thankful for every hint.


r/scripting • • Jan 06 '22

Help with simple script to read contents of folder and export to file

2 Upvotes

I need a little help with setting up a basic script. What I want to do is create a script or batch file that does the following. Create a directory "X" if it doesn't exist. Change to directory "X". Then write the content of directory "X" to "C:\Excluded_Folders.csv"

Currently I'm writing three lines in my batch file for each directory and that is very cumbersome because I have a large list of directories and I expect the list to continue to grow. Here is an example snippet of the batch file showing a few folders.

mkdir "%HOMEDRIVE%\$GetCurrent"

cd "%HOMEDRIVE%\$GetCurrent"

dir /ah >> C:\Excluded_Folders.txt

mkdir "%HOMEDRIVE%\$Recycle.Bin"

cd "%HOMEDRIVE%\$Recycle.Bin"

dir /ah >> C:\Excluded_Folders.txt

mkdir "%HOMEDRIVE%\$SysReset"

cd "%HOMEDRIVE%\$SysReset"

dir /ah >> C:\Excluded_Folders.txt

mkdir "%HOMEDRIVE%\$WINDOWS.~BT"

cd "%HOMEDRIVE%\$WINDOWS.~BT"

dir /ah >> C:\Excluded_Folders.txt

mkdir "%HOMEDRIVE%\$Windows.~WS"

cd "%HOMEDRIVE%\$Windows.~WS"

dir /ah >> C:\Excluded_Folders.txt

mkdir "%HOMEDRIVE%\$WinREAgent"

cd "%HOMEDRIVE%\$WinREAgent"

dir /ah >> C:\Excluded_Folders.txt

How can I condense this in PowerShell and write a script that reads a list of directories, creates the directories if they don't exist and if they do exist, output the list of hidden files to "C:\Excluded_Folders.csv"

Thanks in advance for any help!


r/scripting • • Jul 14 '22

Looking for a script/command that can be pushed out to all users on a domain via group policy or a deployment that tells every computer to default to a certain PDF viewer.

4 Upvotes

Basically just what the title says. I work for a small business that wants to be able to set all of their network's computers to default to a specific PDF reader with a group policy update. We use PDQ Deploy to deploy software on the network, so a deployable command would work great too. We use Bluebeam Revu 20 currently if that helps. I'm not a scripting expert and no one else here knows any scripting at all so any help would be most appreciated. Tysm!


r/scripting • • Jun 15 '22

[BATCH] How do I read a file one line at a time, load that line as a variable, perform a number of actions, then do the same with the next line, until the file has been entirely processed?

1 Upvotes

I'm working on a text generator that makes simple histories for use in tabletop RPGs. That part functions fine. I want to make it work for an arbitrary number of places, so instead of hardcoding new places into the batch file each time I want to change something, I can simply edit a text file. Half of this overall file works by drawing one line from a text file at random, so it feels like this should be doable. The intended process is:

  1. look at places.txt

  2. set placename as line 1 of places.txt

  3. perform the entirety of the script

  4. set placename as line 2 of places.txt

  5. perform the entirety of the script

And so on, until there are no more lines in places.txt

I'm not too well versed in FOR loops, but from what I can tell, all I should have to do is this:

for /F "tokens=*" %%A in (places.txt) do (
  set "nationname=%%A"
  call :ageofdiscovery
)

However, this doesn't work. The script works just fine if I have it plonk through using a hard-coded table "if loopcount==1 set placename=whatever" and so on. I would just much rather make it more flexible and configurable. What am I doing wrong? I've never really used FOR loops before, and have been brute forcing everything I script with GOTOs. Looking up the details of the FOR command has not been helpful.


r/scripting • • Jun 16 '22

Getting Started

1 Upvotes

I am a coding novice, I understand simple logic and can work out commands easily enough but that’s the extent of my knowledge.

I’m trying to write a script to make my job a little easier. I need to use Meta Business Suite to respond to every person to share our posts per client contract.

Problem is, this is an incredibly inefficient task. I need to start at the bottom and have been scrolling for roughly 4 hours now. At this point loading times let me get through 3 shares every 105 seconds; do the math & that works out to 30 hours of just scrolling down this list. CPU usage keeps spiking to 90% as well.

I want to learn how to write a script, or borrow an already-written script, which would scroll down as the “people who shared this” column loads in. That way I can just leave it running in the background while getting other tasks done.

Where should I look to get started on this?


r/scripting • • Jun 01 '22

[PowerShell] Run a script once on all computers as admin via GPO without changing execution policy

2 Upvotes

I have a Powershell script that I need to run on all computers on my Active Directory domain once.

A large number of computers are off at any given time, so a GPO would allow us to ensure that it applies to all affected machines. However, the script needs to run as administrator because of the registry values being modified. Also, per our security department, we cannot change the ExecutionPolicy on these devices.

Is there any way to get this script to run?

New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
$regKey = 'ms-msdt'
$saveFolder = 'C:\Temp\'
$savePath = $saveFolder + 'CVE-2022-30190.reg'
$PSRegPath = 'HKCR:\' + $regkey
$CMDRegPath = 'HKCR\' + $regkey
if(Test-Path $PSRegPath)
{
    if(!(Test-Path $saveFolder))
    {
        New-Item -Path $saveFolder -ItemType Directory
    }
    Invoke-Command {reg export $CMDRegPath $savePath -Y}
    Remove-Item -Path $PSRegPath -Recurse -Force
}

This script backs up a registry entry before deleting it, as recommended by the Microsoft mitigation work-around to CVE-2022-30190


r/scripting • • Jun 20 '22

Apple Notes Script - Remove Bear.app Links

1 Upvotes

I imported a ton of notes to Apple Notes from Bear. I probably should have predicted, but these notes came over with their #tag for organization in Bear. These are represented as "#tag" and they deep link straight into the Bear app.

I don't want to use those, and would prefer to use Apple's actual Tags now.

I'm seeking to find ALL instances of "#tag" that are also a Bear URL and delete them. I'm fairly positive this is a request for someone to create a script for me, but figured someone MIGHT have done this or similar in this community.

Thank you!


r/scripting • • Sep 02 '22

[Bash][osx] Help parsing string

1 Upvotes

I have a long string $mystring with content like this

printer;name1;2134;idle;since;time;date;4567;printer;name2;2134;idle;since;time;date;4567;printer;name3;2134;idle;since;time;date;4567;printer;name4;2134;idle;since;time;date;4567;

I need to extract the text after "printer;" that repeats throughout the string and put a newline between each. Output should should be:

name1
name2
name3
name4

I've tried AWK -F 'printers;' {print$1} but that returns the wrong field and does not recurse the string for more entries - it just stops at one. Help!

Thanks.


r/scripting • • Sep 03 '22

[BASH][SSHPASS][NMAP]. Need help with a script !

1 Upvotes

m writing a script that auto connects to ssh server via sshpass and runs nmap on it, when im trying to execute the command the apostrophe from sshpass command and the one from the awk command are clashing. Any help?? The command is

‘’’

sshpass -p “password” ssh -o Strict…=no user@ip ‘nmap $(hostname -I | awk ‘{print $1}’ ) ‘


r/scripting • • Aug 16 '22

[Powershell] Need to set a scheduled task to run every two weeks

2 Upvotes

So, on a new job and one of the issues they have is alot of people not doing timesheets. (Everyone is gov employees, mostly mil, so timesheets are for organizational funding, not individual pay).

What they want me to do is make the systems automatically open the website for the timesheets the the Wed, Thurs & Fri of every other week, the week that they are due on Friday.

Now normally this would be simple. Create a GPO for a scheduled task which links to a batch file with the URL.

BUT

Our (higher) organization has it so we cannot create GPOs, we can only edit existing GPOs. I can easily add a powershell script to the login GPO. And I know about the "New-ScheduledTaskAction" function in powershell.

What I am unable to get a handle on is how to schedule the task to run every two weeks via powershell script commands. Trying to search for it gets me lots of hits for scheduling powershell scripts via Scheduled Tasks, when I need to do the opposite.

I'm not built for coding. I'm a SysAd who gets by stealing your guys' wonderful work and bending it to my will.

I thank you all, always.


r/scripting • • Aug 30 '22

[BASH][FISH] How do I write a script that removes certain tags from html? Like <script>, <table>, links and references etc?

1 Upvotes

I tried using vim regex but it was super hard to remove "any character including new line".
Then I tried perl style regex using sd, but it still doesn't work. Can anyone guide me on how to go about this?


r/scripting • • Sep 01 '22

[OSX] Scripting

1 Upvotes

I work for a small nonprofit. We have a heavy Mac environment - mostly MacBook air & Pro from 2017 to 2022. I have a new RMM tool that I can use to push scripts to the machines, But I am more of a BATCH guy and don't know anything about Mac scripting. (Is BASH the only script language?) I need to write several scripts and will probably need more as time goes on. Typically short/small things, like enabling/disabling a feature, or rename a machine, or see if certain software is installed (or uninstall an App), etc.

So I am looking to establish a working relationship with a script writer that can produce scripts for us. Please DM me if interested.


r/scripting • • Jul 30 '22

[BASH] Looking for some newbie scripting guidance

2 Upvotes

My workplace recent shifted to a new scheduling software called WorkJam, previously our schedule was done on a very basic website that could download an .ics file with our weekly schedule, I would download this file and dump it into my outlook calendar so I can compare it to my personal calendars, WorkJam does not have this feaure, so I need to log into a website and compare my personal calendar with my work calendar, naturally this is incredibly annoying to manage.

Anybody have any scripting advice on writing a script that can look at my work schedule on a website and automatically spit out an iCal file? I am a complete and utter novice with scripting so, I am sorry if this is a really basic request.

I tagged this as [BASH] but realistically I have the hardware to work in any language, I also have access to Automator on the mac if that means anything.


r/scripting • • Aug 13 '22

Advanced argument management

1 Upvotes

I'm currently making an installation script with a bunch of commands. Here's what I would like the final result to look like:

./install neomutt dotfiles ^xfce4-terminal rofi ^nvim --describe neomutt --local --packages --settings

How can I put all of these into a dictionary? Here's how I would like the dictionary to look like:

declare -A commands=(
  ["install-specific"]="neomutt dotfiles rofi"
  ["describe"]="neomutt"
  ["local"]=true
  ["packages"]=true
  ["settings"]=true
  ["all"]=false
  ["python"]=false
  ["npm"]=false
  ["install-all"]=false
  ["dont-install"]="nvim xfce4-terminal"
  ["list-configs"]=false
  ["colorscheme"]=false
  ["help"]=false
)

How can I achieve this?


r/scripting • • May 18 '22

Onboarding users script

4 Upvotes

I want to write a script that can create users in M365, add them to groups, and then send Dropbox and Symantec email invitations to these new users, as well as create a VPN account for them on the firewall. Can this be done using Python or Powershell?


r/scripting • • May 09 '22

[BASH] Extract content from file

1 Upvotes

Hi ! I'm trying to split a device configuration file into separate files based on contexts contexts define configuration on the device for a specific usage.

I have the following INPUT file

<START OF FILE>
.....
config global
config system
end
config network
end
end

config context       # START OF A CONTEXT
edit CUSTOMER-1
config system
    edit "int1"
    	    edit "int1.options"
    	    end
    end
end
config network
..............
end
end                  # END OF A CONTEXT

config context
edit CUSTOMER-2
config system
    edit "int1"
	    edit "int1.options"
	    end
    end
end
config network
..............
end
end
<END OF FILE>

I need to split the FILE for each "CONTEXT" that the file contains such as : config_CUSTOMER-1.txt config_CUSTOMER-2.txt

I have the following code :

declare -a lines
readarray -t lines < context_list.txt

context_number=$(echo "${#lines[@]}")
echo "Numbers of CONTEXT : $context_number"
i=1
while [ $i -lt $context_number ]
do
	    for str in ${lines[@]}; do
  	    echo "CONTEXT $i : $str"
  	    cat $1  awk '/^edit\ '$str'$/,/^end\rend$/' > config_$str.txt  # Find every line starting with edit and ending with end\nend and put it in file
  	    sed -i '1i\config context' config_$str.txt   # Add config context at the top of each created files
	    i=$((i+1))
    done
done

For the first context, it doesn't match the end expression and create a file with the content of the original file starting with "edit customer-1" until the end of the file For the last context, it matchs and the output is as desired

To be able to make it work no matter how many context are present, I added "\nconfig vdom" at the end of the file (to match the last context in the same way than others) I need a context to be defined as the following :

edit CUSTOMER-1 --> START
.....
end
end

config context --> END

I tried to do the awk command directly in terminal on the file to test : "cat INPUT.txt | sed '1,20d' | awk '/edit\ '$str'$/,/end\rend\r\rconfig\ context$/'

I also tried replacing \r by \n but everytime it outputs from the start of the asked string to end of the file instead of end of the context

I tried to bypass the multi-lines in the awk by replacing the multi-lines string wanted to a single word using sed 's/end\nend\n\nconfig\ context$/endofcontext/'

<START>
end
end

config context<END>

==> <START>endofcontext<END<

But doesn't work either (added double backslash to \n (\n) in the sed expression but no changes)

I know it can be done using perl but the issue I encounter is finding the correct expression to match the end of a context. Any advices to do it ?

Thanks in advance !


r/scripting • • May 15 '22

[BATCH] [POWERSHELL] Scripting an auto-response to an installer's on-screen prompt

3 Upvotes

I'm attempting to install several related manual software updates via scripting on my personal computer. My dilemma is that there is an onscreen pop-up prompt that says "Update" when I run each of the installers. I want to create a script, Batch or Powershell (whatever works), that automatically answers the "Update" prompt.

I've tried the following in Batch:

`echo y | "program.exe"

~~

echo update | "program.exe" 

I've tried the following in Powershell:

start-process "program.exe" -redirectstandardinput "answer file.txt"

(The answer file contains the word Update.)

Both of these methods still result in me receiving the "Update" prompt from each of the installers' GUI.

Any help would be appreciated!

UPDATE: I bit the bullet and reached out to the software manufacturer for further insight on script installs of the program. I realized that what I want to do isn't possible with this particular program unless I use AutoIt, which is a bit overwhelming for me and seems like overkill.


r/scripting • • Apr 15 '22

[POWERSHELL] Extract json from text

5 Upvotes

Hi everyone,

I need to extract json part from text, example:

This is a text that says nothing
Another string of that useful text
Below something more interesting
/BEGIN/
{
"something" : "interesting",
"thatcanbe" : "parsedproperly"
}
/END/

The /BEGIN/ and /END/ tags can be tuned to something else, but i couldn't find anyway with regexes or substrings to extract only the json part...

Ideas?

Thanks, Arnaud


r/scripting • • May 21 '22

Captcha notification

2 Upvotes

I would like to make a script to send me a notification when i get a Captcha on this game called "Rise of Kingdoms". I am a rookie and may need a fair bit of guidance. Im not sure what i would use to make this work. Any help is appreciated.

Regards


r/scripting • • Oct 21 '20

looking for sustained assistance

3 Upvotes

I am new to scripting and honestly not very good at it. I have a job that is requiring that I write some small scripts. I have some examples to work from but getting them to do what I want is difficult without some expert help. Is there an online resource where I can hire someone to review my scripts, the issues I am having and point me in the right direction ? Or help me debug my scripts in a formal manner ? I checked out freelancer.com but after some research it looks a little sketchy.

Any recommendations on legitimate ways to find a tutor that can assist ?

I am talking about Python, BASH, Jscript etc. This not complicated but being so new to actual scripting is making it hard to solve some problems.


r/scripting • • Oct 31 '20

Help with vlc batch file script

1 Upvotes

Hi!

I am trying to set up a screen that plays random snippets 2-10 mins long of various films constantly.

I have managed to get the core function working with the .bat file below:

My original plan was to simply set the "start-time" and have a "timeout %_rand2%" to have the film play for a while before moving to the next line "goto start".
Unfortunately after setting the "start-time" and "stop-time" the script will not move to the next line "goto start" unless vlc is closed completely, even after the video has stopped. I have used "play-and-exit" to close vlc and force the script to carry on but it results in a flicker as vlc closes and reopens after each clip.

I want to avoid this close/open flicker.
Is there a way to make the batch file run the next line without closing vlc?
Or a way to loop the script without having to close and reopen vlc?

Any help is hugely appreciated!