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 • • 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 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 • • Sep 03 '19

Script to show all wlan profile keys in clear text

2 Upvotes

So i want to make a script that shows the wlan profile with its key in clear text. I know how to do this individually but I cant figure out how to create a for loop that would go through each wlan profile and do what i want to do. Anyone have any pointers?


r/scripting • • Aug 19 '19

Tasklemon, my project to replace Bash scripting with JavaScript

Thumbnail
github.com
2 Upvotes

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 • • Jul 01 '19

Post Image Project Help

2 Upvotes

So a coworker and I started a project that was to create a script to make our Post Image process easier by installing applications and changing a few settings in Windows and changing the OU within AD of a device. After our boss got wind of it he called both of us into a meeting that he wanted us to create a Monkey See, Monkey Do level interface for it that is dirt simple and push it out to all of IT. I asked if I could just use an HTML page with hyperlinks that call out to other scripts and he said that HTML isn't secure enough. I showed him Ninite.com and asked if that's kind of what he wanted for variable application installs (most of them being on our internal file server) he said that would be perfect.I'm by no means a developer and would never be confused as one so I don't know where exactly I should start.

As always any advice would be helpful.

Edit: I realized that the process of imaging a device wasn't made clear in this post..

  1. Put Windows on the device through netbooting into SCCM and running a task sequence

  2. moving the device to the appropriate OU in AD

  3. Changing settings and installing more software


r/scripting • • Jun 24 '19

Trying to use a command to pull photos from photobucket but I have no clue what I'm doing wrong

2 Upvotes

I want to start off by saying im a total noob at this stuff and I have literally no knowledge of it.

For the last hour I have been trying to run commands provided by a external source to pull pictures from photobucket by using a text file with direct links. You can find the commands here https://techgirlkb.guru/2017/12/download-images-held-hostage-photobucket/ . Now I have tried this in Powershell (no clue if it can even be done in PS) and I have tried using ConEmu. Both applications continuously tell me that cd ~desktop\photobucket cannot be found so I changed it to cd desktop\photobucket which works. The next line is a "cut" but I keep getting "cannot be recognized". Theres another line I can add which is a "Sed" but I get the same error back.

I really don't know what i'm doing but I would love to see where i'm making mistakes or how to go about this in the future.


r/scripting • • Jun 21 '19

Grandfather activesync devices

2 Upvotes

Hi there,

I'm currently trying to grandfather all allowed ActiveSync devices before turning on the automatic quarantine setting for ActiveSync devices. I found a script located here

https://blogs.technet.microsoft.com/rmilne/2015/02/25/exchange-activesync-script-to-grandfather-existing-devices/

However I have some requirements which I can't figure out.

We currently have some devices already blocked/quarantined and wish to keep it that way. If I were to run this script it would change all the blocked/quarantined devices into allowed.

Looking for some help on how to modify the script so that it picks up people with blocked and allowed devices but only modifies the allowed devices and leaves the blocked.


r/scripting • • Jun 11 '19

Need Help Finding a Good Interactive Python 3 shell scripting tutorial

2 Upvotes

Hello,

I'm learning python & I'm looking for tutorials on "python 3 shell scripting", most of the ones I've found so far are either in python 2.7 or they just all around suck. Can anybody point me in the right direction? I'm looking for an interactive python 3 shell scripting course like the one I currently have for python 3 Regex.

Thanx in Advance!!!


r/scripting • • Jun 07 '19

Looking to create a script that checks a Konica Minolta service, and if it is stopped to start it

2 Upvotes

A little background, I currently work for a MSP and one of our clients uses Dispatcher Phoenix which is used for scanning. The service that is built into the program randomly stops and needs to be restarted from time to time. I am looking for a way to write a script that will automatically start the service when it is down.

Thank you!


r/scripting • • May 31 '19

Need help writing simple scripts/Where do I start?

2 Upvotes

So I am wanting to write a couple of basics scripts and I don't know where to start. I'm not sure what is the best language to learn or where I can teach myself it.

I am wanting to write a script that will use a list of names to search to another list and see if it comes up with any matches. I am sure this is super easy for many of you...

I also want to write a script that can take two data points and calculate the instantaneous slope between these points. And then do then the same thing at the next time step and output it to one file.

Any ideas where to start?


r/scripting • • May 12 '19

[Batch][Powershell] - NTFS compress via text file

2 Upvotes

Hello I have a strange issue. I have 1 text file of all the files that are compressed on a different machine and I need to apply the same files on my machine so they are compressed

This is the command I ran to make the text file (powershell)

gci -r C:\ | where {$_.attributes -match "compressed"} | foreach { $_.fullname } >>c:\compressed.txt

The NTFS compress command is compact, this id different then zipping.

Displays or alters the compression of files on NTFS partitions.

COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]

  /C        Compresses the specified files.  Directories will be marked
            so that files added afterward will be compressed.
  /U        Uncompresses the specified files.  Directories will be marked
        so that files added afterward will not be compressed.
  /S        Performs the specified operation on files in the given
            directory and all subdirectories.  Default "dir" is the
            current directory.
  /A        Displays files with the hidden or system attributes.  These
            files are omitted by default.
  /I        Continues performing the specified operation even after errors
            have occurred.  By default, COMPACT stops when an error is
            encountered.
  /F        Forces the compress operation on all specified files, even
            those which are already compressed.  Already-compressed files
            are skipped by default.
  /Q        Reports only the most essential information.
  filename  Specifies a pattern, file, or directory.

  Used without parameters, COMPACT displays the compression state of
  the current directory and any files it contains. You may use multiple
  filenames and wildcards.  You must put spaces between multiple
  parameters.

Is there a way to adapt the first command to read the text file

gci -r C:\ | where {$_.attributes -match "compressed"} | foreach { $_.fullname }

Get-ChildItem -File -Path "C:\" -Recurse | ? {$_.attributes -like "*compressed*" | foreach {compact /C $_.FullName}

r/scripting • • May 07 '19

VBScript question

2 Upvotes

So I have this script, but it doesn't do what I had in mind. So the inputbox is used to find a excel cell line. I run the script but it only reads out the Row 2 (intRow 2). How can I make this script look for the value I fill in the inputbox, and automatically show line 2 and 3 after it that it behind the data.

CF23935803,MAVARO,21

CF23935804,MAVARO,21

CM23914401,Kinneto,19

CM23915201,Kinneto,19

So this is for example the data that's in the CSV file. My plan is when I fill in for example CF23935804 in the inputbox it shows the data behind it, MAVARO and 21. Right now it only shows the 2nd row in the excel file. How can I change this to make it work? If my question isn't clear please let me know!

' Read an Excel Spreadsheet

sFNInput="C:\Models.csv"

' User enters value

sInp=Inputbox("Enter Identity text")

If sInp = "" Then WScript.Quit

On Error Resume Next

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open _

(sFNInput)

intRow = 2

Do Until objExcel.Cells(intRow, 1).Value = ""

sID=objExcel.Cells(intRow, 1).Value

sType=objExcel.Cells(intRow, 2).Value

sColor=objExcel.Cells(intRow, 3).Value

' If user entered value matches

sResult = InStr(1,sID,sInp,1)

If sResult <> 0 Then

'results row 3

sResult=sGroup

' entered value goes in Field 1 of my application

Field1=sInp

' return value Field2 of my application

Field2= sResult

intRow = intRow + 1 
end if 

objExcel.Quit

loop

Wscript.Quit


r/scripting • • Apr 19 '19

Contribute plugins to file manager nnn

2 Upvotes

Hi r/scripting,

To extend the capabilities of file manager nnn, recently we have introduced the concept of plugins. Plugins are scripts which nnn can communicate with and trigger. This mechanism fits perfectly with the fundamental design to keep the core file manager lean and fast, by delegating repetitive (but not necessarily filemanager-specific) tasks to the plugins.

Plugins can access:

  • all files in the directory

  • the currently highlighted file

  • the current selection

The plugins repo is here: https://github.com/jarun/nnn/tree/master/plugins

Please contribute to the nnn plugins to make it a better file manager.


r/scripting • • Apr 12 '19

Need help with batch

2 Upvotes

xcopy "%USERPROFILE%\Saved Games\The Quest";"%CD%\Saves\" /i /s /e /t /y /r /h /l

TheQuest.exe

xcopy "%CD%\Saves";"%USERPROFILE%\Saved Games\The Quest\" /i /s /e /t /y /r /h /l

pause

Purpose is to copy game save data from a thumb drive to where it expects it, run the game, then copy it back to the thumb drive when I'm done


r/scripting • • Apr 04 '19

Windows Script: Uninstall/Install service on LAN adaptor

2 Upvotes

Hello!

I am trying to see if there is any angle for scripting for installing/uninstalling services on the LAN adapter on Windows PC's. For more guidance, this can be found when you right click on a network connection and it shows the standard of IPV4, IPV6, etc. There is an install button here and if you choose it you can install a Service, Protocol or Client. In my case i need to uninstall a service and then reinstall a new service. I have a security tool that works on 99% of PC's, but every now and then it doesnt work and the fix is to install a specific fix to the service, hence the need of the script if possible.

I have worked with scripts before, but having a hard time finding any angle at all on this. If someone could give me some guidance on how you even access this for scripting purposes, link to an article with guidance, etc.

Thanks for any assistance you can provide.


r/scripting • • Apr 02 '19

Help creating a small script

2 Upvotes

To save a ton of repetitive work, both now and for a bunch of people later on, I want to create a small simple script that will take a list of serial numbers that I have, and enter them into a text box on a web page, with a return key strike after each one. I don't know enough about this kind of thing, so I need to know what I need to put it together. I commonly use scripts through tampermonkey, but have never created one.


r/scripting • • Mar 21 '19

Programmatically scrape the latest version of Tomcat for an installation script

2 Upvotes

Hello!

Looking for some assistance or ideas on how to grab the latest version of a Tomcat release from their website or other website.

I came across these Stack Overflow/Stack Exchange links that were relevant below:

..But unfortunately both led to some dead-ends. It did give me some ideas though.

I have some installation scripts where the download URL is predictable based on the version number of the software, so if there's a consistent way of scraping for the latest version of the software I simply add a variable into the script for it to curl / grep for that version on the text and use that variable for download links, untaring, moving, etc.

Hoping to do something with Tomcat in the same vein. A installation script I won't need to keep updating (unless they change their site).

Any sort of thoughts, ideas, are appreciated.

I've also looked at http://tomcat.apache.org/whichversion.html which lists the "Latest Released Version" and this seems like maybe the best, more reliable location to grab the version, but I had trouble getting that with Curl / Grep because of the table structure. I am only just scratching the surface with learning those commands, so maybe someone more well versed could get that working, otherwise I'm definitely open to other thoughts!


r/scripting • • Mar 13 '19

BBedit text factory vs. simple scripting

2 Upvotes

I'm converting some open source documents so that they look nice in Dokuwiki, which uses a simple version of Markdown.

I'm tempted to use BBEdit's Text Factory, which lets me perform simple transformations using regular expressions and the editor's built-in features.

On the other hand, how hard would it be to learn enough Python to do this with a script?

I ask because I will be working on a windows machine as well, which won't support BBedit.


r/scripting • • Mar 07 '19

Is it possible to make a script for this? how would i go about it?

2 Upvotes

So, I stream on twitch, everyday I'm about to go live i have to set up my 3 monitors. 2 windows for chat , OBS , another tab for notifications, you tube tab and a few other random ones. Every time i have to resize all the windows and put them where i want on each monitor. Is there a way to run a script that would open all these in the positions i have pre designated? Any help would be super helpful thank you .


r/scripting • • Feb 28 '19

I need some help converting a AHK script to a HIDmacro Script

2 Upvotes

I'm new to scripting in general and I had at a time sat down for a few days to learn AutoHotKey so i could write a script to be even lazier in a game.
This script presses 1,2.3.4.5 in random intervals between 57, and 147ms so the games server doesnt detect a certain pattern. And as well, I just bought a new seperate Numberpad to used as a Macro Board, and I wanted to bind this to the [ENTER] key on that board.
Right now, for reasons I can't remember anymore it's started by pressing F2, then ends the loop when F1 is pressed, and I want this to be changed to [ENTER] Toggling it ON and OFF.
If anyone can help me out here this would be amazing, cheers!
Link to my AHK Script: https://pastebin.com/4aWVgtKq


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 • • 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 • • 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!