Category: Batch File Scripting
Batch file set year into the future
Simple batch to set a variable 2 years into the future, works out Year, plus 2 and then adds to the date Credits: SS64 set /a YEARVAR=%DATE:~+8,2% set /a YEARVAR=%YEARVAR%+2 set YEARVAR=%YEARVAR% set DATEVAR=%DATE:~0,8% set “EXP_DATE=%DATEVAR%%YEARVAR%”
Powershell issue with output characters changing to ?
On PowerShell command pipe to export CSV add Encoding Unicode if characters change to ? Credit: Idera execute xp_cmdshell ‘powershell -Command “Get-ChildItem -File -Path @path -filter *.* -Recurse | ForEach-Object {[PsCustomObject]@{Fullname = “$($_.FullName)”; LastWriteTime = “$($_.LastWriteTime)”}} | Sort Fullname -Descending | Export-Csv -Path @CSVFile -NoTypeInformation -Encoding unicode”‘ If using BULK INSERT ensure widechar is used…
Maintain regtrans-ms and blf files generated by Georgia UTS sessions
A little script I schedule for servers using Georgia UTS. Below I use Robocopy to move files older than 3 days, to avoid anyone currently logged in. For me I expect users to be logged on for no more than a day, active user files should therefore be untouched. echo This Batch Files removes .regtrans-ms…
Georgia Telnet or SSH generate a list of users for GS_L_User.txt
Georgia Telnet can restrict the number of users that connect to Telnet or SSH. I am lazy so I tend to generate a list based off our user logon scripts folders, however I do of course take a backup and test it afterwards. echo Change to the drive where your Georgia logon scripts are located…
Creating a shortcut to a non existent location on Windows
Credit: ServerFault Credit: Craig Tolley I came across the need to create a shortcut to a non existent file share (Where a wireless network had a different ip range on a different site). I thought Windows would let shortcuts for SMB shares be created if they didn’t exist, but Windows 10 insisted the share had…
Batch script to help with launching files for correct version of Windows
We encountered an issue during a migration to Windows 10 where I had missed a program which had hard coded links, these no longer worked due to Microsoft Access being a newer version. I generated a simple script so we could change the hard coded links to allow it to select the correct version, all…
Generate a text file with subfolders in a location on explorer
I needed to generate a list of folders and their subfolders, I used a simple command for dir command and slapped into a text file. Below replaced with the folder you want to get the list from (i.e C:\Users\Default) and replace with where you want to save a textfile (i.e C:\textfile.txt). dir /b /s /a:d…
Display advanced properties of scheduled tasks in command line
The following command requests a detailed display of the tasks on the local computer. It uses the /v parameter to request a detailed (verbose) display and the /fo LIST parameter to format the display as a list for easy reading. You can use this command to verify that a task you created has the intended…
A simple batch file which compresses every folder into a 7z Archive
For backing up old files I tend to sort into lots of different folders, anything I am finished with I put in a 7zip Archive The following batch makes use of a For loop in the batch, uses 7-zip with Ultra Compression and names the archive the same as the folder. for /D %%X in…
Rebuild a V1 DBCapture Database Queue
We have an issue where on a rare occasion a scan from V1 DBScanner to DBCapture can corrupt the queue and cause DBCapture Admin to state it is unable to open a document rendering the whole application unusable. I have a batch script to perform some maintenance. Over time I have commented out lines which…