How to read different contents from a text file - batch-file

I need to read the ID from a file like this:
BitLocker Drive Encryption: Configuration Tool version 10.0.16299
Copyright (C) 2013 Microsoft Corporation. All rights reserved.
Volume C: [OSDisk]
All Key Protectors
External Key:
ID: {31116007-D1FB-43CC-A89C-927487BD5F00}
External Key File Name:
31116007-D1FB-43CC-A89C-927487BD5F00.BEK
Numerical Password:
ID: {C7948F32-F2F0-4E55-AD2E-06E982DFDB4F}
Password:
xxxx-xxxxx-xxxxx-xxxxxx-xxxxx-xxxx-xxxxx-xxx
TPM:
ID: {6497FF93-F678-4317-B5D7-423E9D682BF0}
PCR Validation Profile:
0, 2, 4, 8, 9, 10, 11
and then run the following command to to export the keys to AD for all IDs
manage-bde -protectors -adbackup c: -id {C7948F32-F2F0-4E55-AD2E-06E982DFDB4F}

If you're not willing to utilise another built-in scripting language for this, and your file to read uses Windows standard line endings, I have an alternative idea.
Instead of directly searching for lines with ID: {…, you may be able to search for <Anything><Carriage Return><Line Feed><Space(s)><Password:>. You could further refine <Anything> should you feel the need, but in this case I do not think it's necessary:
#Echo Off
SetLocal DisableDelayedExpansion
Set "Src=input.txt"
Set "Str=Password:"
Set "ID="
(Set LF=^
% 0x0A %
)
For /F %%A In ('Copy /Z "%~f0" Nul')Do Set "CR=%%A"
SetLocal EnableDelayedExpansion
FindStr /RC:".*!CR!*!LF! *%Str%" "%Src%">"%TEMP%\_$.tmp"
EndLocal
For /F "UseBackTokens=2Delims={}" %%A In ("%TEMP%\_$.tmp")Do Set "ID={%%A}"
Del "%TEMP%\_$.tmp"
If Not Defined ID GoTo :EOF
manage-bde -protectors -adbackup c: -id %ID%
In the example above, I have used input.txt as the name of the text file you're reading, please modify that as needed.

FOR /f "tokens=2delims={}" %%a IN ('findstr /x /r /c:" *ID: {.*}" "%filename1%"') DO ECHO manage-bde -protectors -adbackup c: -id {%%a}
where filename1 contains the filename you are examining and the command is being echoed. Remove the echo keyword to execute manage-bde.
The findstr looks for lines that exactly match the pattern [spaces]ID: {string} and assigns the string between {} to %%a, then displays the required command line, reapplying the {}

a pure batch script, which takes advantage of the fact, you look for the key immediately after a "trigger line" (Numerical Password:)
#echo off
setlocal
set "flag="
for /f "tokens=*" %%a in (t.txt) do (
if defined flag (for %%b in (%%a) do set "key=%%b") & goto :found
if "%%a" == "Numerical Password:" set "flag=yes"
)
echo not found & goto :eof
:found
echo %key%

Perhaps use a windows script to handle the task? This can be executed directly, using wscript, or from a batch file using cscript:
cscript //nologo myscript.js
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile("C:\\myfile.txt", 1);
var content = file.readAll();
// Do something with file content
file.close();

You might be able to get what want with Regular Expressions and FindStr. Partial solution since I'm lazier than you. ;)
c:\projects>findstr {[0-9A-F/-]*} data.txt
ID: {31116007-D1FB-43CC-A89C-927487BD5F00}
ID: {C7948F32-F2F0-4E55-AD2E-06E982DFDB4F}
ID: {6497FF93-F678-4317-B5D7-423E9D682BF0}

EDIT: I overlooked that all IDs and created a solution based on the example line
The following PowerShell one liner will extract the ID from a text file .\BitLocker.txt
PoSh> Select-String -Path .\BitLocker.txt -Pattern 'Numerical Password' -Context 0,1|ForEach-Object {($_.Context.Postcontext.Trim() -split ' ')[1]}
{C7948F32-F2F0-4E55-AD2E-06E982DFDB4F}
To be on topic wrapped in a batch:
#Echo off
For /f "usebackq delims=" %%A in (`
powershell -NoP -C "Select-String -Path .\BitLocker.txt -Pattern 'Numerical Password' -Context 0,1|% {($_.Context.Postcontext.Trim() -split ' ')[1]}"
`) Do Set "ID=%%A"
manage-bde -protectors -adbackup c: -id %ID%

Related

Create a set of folders with cmd - Set a loop variable with a space

I don't know if its age or lack of practice. Either way I cannot wrap my head around this issue. I am trying to set a subroutine but the string that I am passing along are being split because of the space in string 3 and 4.
SET SubA=String1,String2,String 3,String 4
FOR %%A IN (%SubA%) DO MD "%%A"
I've tried parenthesis around the string
The <> brackets like Microsoft says to use. I have also tried this line below without success.
setlocal enableDelayedExpansion
For /F "tokens=* delims=" %%A IN (%Var%) DO MD "%%A"
Also I would love if possible could I make an list, possibly with an array. Like in Power shell I could do this. I really need to keep in the same batch file so the user could edit the list. I am aware that I could use caret but the easier I can make it for my client the better.
$Folders (
String1
String2
String 3
String 4
)
Edit: My desired result is to have this script create a set of folders like those pictured.
The simplest pure batch-file solution that doesn't require trickery is to use for's ability to enumerate space-separated tokens.
For this to work as intended, tokens that themselves contain spaces must be double-quoted:
#echo off & setlocal
:: Space-separated list of folder names, with names that contains
:: spaces themselves double-quoted.
SET SubA=String1 String2 "String 3" "String 4"
:: Loop over the list elements and create a directory for each.
FOR %%A IN (%SubA%) DO MD %%A
As Compo's helpful answer implies, you could actually pass this list to a single invocation of
MD: MD %SubA%
Unfortunately, as far as I know, batch files do not offer a convenient way to define lists in a one-item-per-line format.
However, you could provide the list of names via an external file, with each name on its own line (no double-quoting needed), which can then be parsed with for /f; e.g.:
#echo off & setlocal
:: Determine the full path of the file "names.txt"
:: located in the same folder as this batch file.
set "nameList=%~dp0names.txt"
:: Loop over all names in the file and call `md` with each.
for /f "usebackq delims=" %%n in ("%nameList%") do md "%%n"
And input file names.txt would then contain something like:
String1
String2
String 3
String 4
The simplest way to 'make' your directories is probably like this:
Set "SubA=String1,String2,String 3,String 4"
MD "%SubA:,=" "%" 2>NUL
As for working with the initial variable, and using it array like, you could do it like this:
#Echo Off & SetLocal EnableExtensions EnableDelayedExpansion
Set "SubA=String1,String2,String 3,String 4"
For /F "Delims==" %%G In ('"(Set Index[) 2>NUL"') Do Set "%%G="
Set "i=0"
Set "Index[!i!]=%SubA:,=" & Set /A i += 1 & Set "Index[!i!]=%"
(Set Index[) 2>NUL && Pause
Or you could do it like this:
#Echo Off & SetLocal EnableExtensions EnableDelayedExpansion
Set "SubA=String1,String2,String 3,String 4"
For /F "Delims==" %%G In ('"(Set Index[) 2>NUL"') Do Set "%%G="
Set "i=-1"
For %%G In ("%SubA:,=","%") Do (Set /A i += 1
Set "Index[!i!]=%%~G")
(Set Index[) 2>NUL && Pause
Here is another way to create the directories using the PowerShell that is already on your system if it is still supported by Microsoft. When you are satisfied that the correct directories will be created, remove the -WhatIf from the mkdir command.
SET "SubA=String1,String2,String 3,String 4"
powershell -NoLogo -NoProfile -Command ^
"'%SubA%'.split(',') | ForEach-Object { mkdir $_ -WhatIf | Out-Null }
A better way would be to test to see if the directory already exists before trying to create it.
SET "SubA=String1,String2,String 3,String 4"
powershell -NoLogo -NoProfile -Command ^
"'%SubA%'.split(',') | ForEach-Object {" ^
"if (-not (Test-Path -Path $_)) { mkdir $_ | Out-Null }" ^
"}"

RegEx works on Online Simulator but not inside BatchFile with findstr

I was trying to setup a batch-file that uses findstr to kill all lines with a certain pattern. The sourcefile i want to analyse looks like this (i changed all values except of the 16th to numbers, usually they are names, urls, empty or single characters like Y/N):
ProductCode|SkuID|Bestellnr|ProductName|locale_de-DE_ProductName|locale_it-IT_ProductName|locale_nl-NL_ProductName|locale_fr-FR_ProductName|locale_en-GB_ProductName|locale_da-DA_ProductName|locale_cs-CZ_ProductName|locale_sv-SE_ProductName|locale_pl-PL_ProductName|locale_sk-SK_ProductName|ProductType|ProduktLink|OnlineAvailability|ProductNumber|IsProdukt|TerritoryAvailability|Category|SubCategory|ImageLink|Status|Flag0|Flag1|Flag2
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Y|17|18|19|20|21|22|23|24|25|26
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|N|17|18|19|20|21|22|23|24|25|26
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|N|17|18|19|20|21|22|23|24|25|26
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Y|17|18|19|20|21|22|23|24|25|26
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Y|17|18|19|20|21|22|23|24|25|26
I just want to exclude all lines that have a N in the 16th parameter. Therefore i came up with a regex pattern that does this:
^([^|]*\|){16}N
Demo that RegEx works (online ressource)
https://regex101.com/r/mE5HVR/1/
When i try to use this feature with findstr like this:
FINDSTR /V "^([^|]*\|){16}N" H:\BatchTest\LineProcessing\myfile.txt >H:\BatchTest\LineProcessing\result.txt
pause
exit
I always get the full file and it seems like regex is not even used. Can anybody point me into the right direction where i can search my mistake? i tried getting more information with this What are the undocumented features and limitations of the Windows FINDSTR command? post but i couldn't find my flaw or oversaw it.
Any help appreciated
Invoke powershell as a tool from batch:
#Echo off
Set "FileIn=H:\BatchTest\LineProcessing\myfile.txt"
Set "FileOut=H:\BatchTest\LineProcessing\result.txt"
powershell -NoP -C "Get-Content '%FileIn%' |Where-Object {$_ -notmatch '^([^|]*\|){16}N'}" >"%FileOut%"
pause
exit
Using aliases with powershell could shorten the command
powershell -NoP -C "gc '%FileIn%'|?{$_ -notmatch '^([^|]*\|){16}N'}" >"%FileOut%"
According to the documentation, findstr has got a very limited support of regular expressions.
You might want to try something like this:
findstr /V "^[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|N|" "myfile.txt"
But unfortunately, this results in an error (FINDSTR: Search string too long.), because there are too many character classes [] specified, I think (refer to the useful thread you already referenced in your question: What are the undocumented features and limitations of the Windows FINDSTR command?).
However, I could think of a work-around using a for /F loop to read the file and remove all 16 columns that precede the one of interest; this works only in case none of the preceding columns are empty:
#echo off
set "HEAD=" & set "FLAG="
for /F "usebackq tokens=1-16* delims=| eol=|" %%A in ("%~1") do (
if not defined HEAD (
set "HEAD=#" & set "FLAG=#"
) else (
set "LINE=%%Q"
cmd /V /C echo(!LINE!| > nul findstr "^N|" || set "FLAG=#"
)
if defined FLAG (
echo(%%A^|%%B^|%%C^|%%D^|%%E^|%%F^|%%G^|%%H^|%%I^|%%J^|%%K^|%%L^|%%M^|%%N^|%%O^|%%P^|%%Q
set "FLAG="
)
)
This makes the interesting column to appear as the first one, so findstr can be used now.
Or here is another approach not using findstr at all:
#echo off
set "HEAD=" & set "FLAG="
for /F "usebackq tokens=1-17* delims=| eol=|" %%A in ("%~1") do (
if not defined HEAD (
set "HEAD=#" & set "FLAG=#"
) else (
if not "%%Q"=="N" set "FLAG=#"
)
if defined FLAG (
echo(%%A^|%%B^|%%C^|%%D^|%%E^|%%F^|%%G^|%%H^|%%I^|%%J^|%%K^|%%L^|%%M^|%%N^|%%O^|%%P^|%%Q^|%%R
set "FLAG="
)
)
If any of the column could be empty, you could use the following adapted code:
#echo off
set "LINE="
for /F usebackq^ delims^=^ eol^= %%L in ("%~1") do (
if not defined LINE (
set "LINE=%%L"
echo(%%L
) else (
set "LINE=%%L"
setlocal EnableDelayedExpansion
for /F "tokens=17 delims=| eol=|" %%K in ("_!LINE:|=|_!") do (
endlocal
set "ITEM=%%K"
setlocal EnableDelayedExpansion
)
if not "!ITEM:~1!"=="N" echo(!LINE!
endlocal
)
)
This prefixes every item by an underscore _ intermittently before extracting the value and checking it against N, so no column appears empty to for /F.
User aschipfl has explained why both the simple regex and the workaround regex fail. There is no simple solution using FINDSTR.
You can use my JREPL.BAT regex utility to easily solve the problem. JREPL is pure script (hybrid JScript/batch) that runs natively on any Windows machine from XP onward - No 3rd party exe file is required.
From the command line you could simply use:
jrepl "^([^|]*\|){16}(?!N\|)" "" /k 0 /f myfile.txt /o result.txt
Within a batch file you need to use CALL, which will unfortunately double the quoted ^. The \XSEQ is added so that the extended escape sequence \c can be used in place of ^.
call jrepl "\c([\c|]*\|){16}(?!N\|)" "" /k 0 /xseq /f myfile.txt /o result.txt
The solution(s) above only preserve lines that have at least 17 columns and do not have N as the 17th column; which means it will exclude lines that do not have 17 columns.
If you want to use your original strategy of simply excluding lines that have N as the 17th column, then
jrepl "" "" /exc "/^([^|]*\|){16}N\|/" /k 0 /f myfile.txt /o result.txt
or
call jrepl "" "" /exc "/\c([\c|]*\|){16}N\|/" /k 0 /f myfile.txt /o result.txt
/XSEQ is not required because the /EXC regex automatically supports the extended escape sequences.
To supplement my earlier comment and to go alongside the existing PowerShell answer, here's a batch file line which utilises PowerShell but bypasses the need to perform a RegEx.
It reads the file as a pipe delimited csv and outputs the lines whose OnlineAvailability field matches Y, (can be modified to -NotMatch 'N'):
#PowerShell -NoP "IpCSV 'H:\BatchTest\LineProcessing\myfile.txt' -Del '|'|?{$_.OnlineAvailability -Match 'Y'}|EpCSV 'H:\BatchTest\LineProcessing\result.txt' -NoT -Del '|'"
The result should be a properly formed csv, with doublequoted fields.
If you would prefer not to have those doublequoted fields, perhaps this modification would be suitable:
#PowerShell -NoP "IpCSV 'H:\BatchTest\LineProcessing\myfile.txt' -Del '|'|?{$_.OnlineAvailability -Match 'Y'}|ConvertTo-CSV -NoT -Del '|'|%%{$_ -Replace '""',''}|Out-File 'H:\BatchTest\LineProcessing\result.txt'"

Batch: search for files with certain extension, owner, fullpath and last write access and output in CSV

I'm trying to create a CSV with fullpath\filename, file owner and last write access (modification date) of all txt and html files from all hard drives of a data server.
Here's what I got so far:
set pgm=%~n0
set log=%~dpn0.log
set host=%COMPUTERNAME%
set csv=%host%.csv
set dir=D:\BME
if not exist "%csv%" type nul>"%csv%"
for /f "delims=;" %%a in ('dir /b/s %dir%\*.txt, %dir%\*.html') do (
>>%csv% echo "%%a"
)
That outputs the path + filename of all found txt and html files of a certain folder in a CSV. I tried this command to get the hard drives:
wmic logicaldisk where drivetype=3 get caption
But I can't get my head around how to store that in a variable or file and loop through it and also retrieve the owner and last modification date and put it into a new column of the csv file.
I can't get my head around how to store that in a variable
Use the following batch file.
GetDrives.cmd:
#echo off
setlocal enabledelayedexpansion
rem skip=1 to remove the header
rem findstr to remove blank lines
for /f "skip=1" %%d in ('wmic logicaldisk where drivetype^=3 get caption ^| findstr /r /v "^$"') do (
set _drive=%%d
echo !_drive!
)
endlocal
Notes:
Be careful when using drivetype=3 as I have a removable drive of type 3. In the below output C: is a fixed hard disk and F: is a removable external USB drive.
Replace echo !_drive! as appropriate with a modified version of your existing code.
Example Output:
F:\test>GetDrives
C:
F:
F:\test>
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
enabledelayedexpansion - Delayed Expansion will cause variables to be expanded at execution time rather than at parse time.
for /f - Loop command against the results of another command.
wmic - Windows Management Instrumentation Command.
DavidPostill answered how-to store wmic logicaldisk … output in a variable;
to retrieve file last modification date: use echo "%%a","%%~ta" in your script using %~t Parameter Extension;
to retrieve file owner: echo "%%a","%%~ta","!_owner!" where _owner variable comes from getRealOwner subroutine based on modified schletti2000's answer Get ownership information from command line by using wmic.
The script:
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
set "pgm=%~n0"
set "log=%~dpn0.log"
set "host=%COMPUTERNAME%"
set "csv=%host%.csv"
set "dir=D:\BME"
set "dirmask=%dir%\*.txt, %dir%\*.html"
rem if not exist "%csv%" type nul>"%csv%"
>"%csv%" (
for /f "delims=;" %%a in ('dir /b/s %dirmask% 2^>NUL') do (
set "_fFullPath=%%~a"
set "_fLastWrite=%%~ta"
set "_fOwner="
call :getRealOwner
SETLOCAL EnableDelayedExpansion
echo "!_fFullPath!","!_fOwner!","!_fLastWrite!"
ENDLOCAL
)
)
)
type "%csv%"
goto :continue
:getRealOwner
SET "ESCAPED=%_fFullPath:\=\\%"
SET "UNDELIMITED="
for /F "skip=2 delims=" %%g in ('
wmic path Win32_LogicalFileSecuritySetting where Path^="%ESCAPED%" ^
ASSOC /RESULTROLE:Owner /ASSOCCLASS:Win32_LogicalFileOwner ^
/RESULTCLASS:Win32_SID 2^>NUL
') do (
SET "UNDELIMITED=%%g"
call :process_wmioutput
)
if NOT defined UNDELIMITED set "_fOwner=???"
exit /B
:process_wmioutput
SET "DELIMITED=%UNDELIMITED: =•%"
FOR /F "delims=• tokens=10,12" %%G in ("%DELIMITED%") DO set "_fOwner=%%H\%%G"
exit /B
:continue
I used next settings to demonstrate various output:
set "dir=D:"
set "dirmask=%dir%\loc*.vbs %dir%\bcd*.log %dir%\act*.xsl %dir%\diag*.xml %dir%\chec*.csv"
Output - non-privileged cmd window:
==> D:\bat\SO\39034430.bat
"D:\odds and ends\tempx\links\testDJ\LocUsers.vbs","mypc\user","25.12.2014 00:13"
"D:\tempWin\ActivityLog.xsl","NT AUTHORITY\SYSTEM","24.02.2016 13:12"
"D:\tempWin\CompatTelemetryLogs\diagerr.xml","???","12.08.2015 03:17"
"D:\tempWin\CompatTelemetryLogs\diagwrn.xml","???","12.08.2015 03:17"
"D:\test\check_acl.csv","BUILTIN\Administrators","06.03.2016 14:28"
Output - privileged (run as administrator) cmd window:
=ADMIN=> D:\bat\SO\39034430.bat
"D:\odds and ends\tempx\links\testDJ\LocUsers.vbs","mypc\user","25.12.2014 00:13"
"D:\tempWin\ActivityLog.xsl","NT AUTHORITY\SYSTEM","24.02.2016 13:12"
"D:\tempWin\CompatTelemetryLogs\diagerr.xml","NT AUTHORITY\SYSTEM","12.08.2015 03:17"
"D:\tempWin\CompatTelemetryLogs\diagwrn.xml","NT AUTHORITY\SYSTEM","12.08.2015 03:17"
"D:\test\check_acl.csv","BUILTIN\Administrators","06.03.2016 14:28"

Find text within string line

I have a text file, that has some text with this syntax:
mytextfile.txt:
websiteurl1 username1 password1
websiteurl2 username2 password2
websiteurl3 username3 password3
And so on....
And I'd like to be able to find username and password strings by pointing the websiteurl, so let's say I tell the batch file,
find websiteurl3, it should print the username3 and password3
and I was able to write a "FOR LOOP" but I am not sure how to use the syntax of the loop, as my code finds only the last line always, here is what I have:
FOR /F "tokens=2,3 delims= " %%A IN (URL.txt) DO IF EXIST URL.txt (set WEBUserName1=%%A) && (SET WEBUserPass1=%%B)
pause
echo Username:"%WEBUserName1%"
echo Password:"%WEBUserPass1%"
pause
exit
I know the loop is looking on the "URL.txt" for the tokens 2 and 3, and then sets the variables accordingly, what I'd like to know, is how I can use the loop, or if needed, any other command to be able to:
Find the "URL.txt file
Then find the specific string, in this case, the first word of the specified string line
Then find tokens 2 and 3 of that string line.
And I'd like to be able to find username and password strings
Use the following batch file.
test.cmd:
#echo off
setlocal enabledelayedexpansion
for /f "tokens=2,3" %%a in ('type mytextfile.txt ^| findstr "%1"') do (
echo Username:"%%a"
echo Password:"%%b"
pause
exit
)
endlocal
Notes:
Pass the website URL string as a parameter to the batch file.
findstr is used to find the matching line from the file, so we only need to parse a single line using for /f.
Example usage and output:
F:\test>type mytextfile.txt
websiteurl1 username1 password1
websiteurl2 username2 password2
websiteurl3 username3 password3
F:\test>test websiteurl3
Username:"username3"
Password:"password3"
Press any key to continue . . .
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
findstr - Search for strings in files.
for /f - Loop command against the results of another command.
type - Display the contents of one or more text files.
bad way, but this too work:
#echo off
setlocal
set srch_site=websiteurl2
FOR /F "tokens=1,2,3 delims= " %%A IN (URL.txt) DO (
IF EXIST URL.txt (
if "%%A"=="%srch_site%" (
(set WEBUserName1=%%B) && (SET WEBUserPass1=%%C)&goto:stdout
)
)
)
:stdout
pause
echo Username:"%WEBUserName1%"
echo Password:"%WEBUserPass1%"
pause
exit
May I offer you a different approach?
The code below get all usernames and passwords and store they in two vectors:
#echo off
setlocal EnableDelayedExpansion
for /F "tokens=1-3" %%A in (URL.txt) do set "User[%%A]=%%B" & set "Pass[%%A]=%%C"
After that, you may test if the username and password of a certain site was given this way:
set "site=websiteurl3"
if defined User[%site%] echo The site "%site%" have username and password
... or display their values this way:
echo Username:"!User[%site%]!"
echo Password:"!Pass[%site%]!"
You may review a detailed explanation of array management in Batch files at this post.
You get the last line, because you process the whole file. Filter your textfile and process only that one line:
set "site=websiteurl2"
FOR /F "tokens=2,3 delims= " %%A IN ('find "%site%" URL.txt') DO (
set "usr=%%A"
set "pwd=%%B"
)
echo %usr%, %pwd%

Is it possible to capture a password in cmd Net Use?

bat script to get a users name and password to connect to shared network drives, the key element is:
net use u: \\server\users\%UserName% * /user:%UserName% /persistent:no
This works great as the password prompt is requested by the "*" which is hidden from view and I have already captured the user's login name. Mapping to other locations on the same server works without any further user input but as soon as I map to another server the user will be prompted to input their password again.
Is there anyway I can capture the entry typed at "*" to apply to a string for the other servers?
Thanks.
Thanks for the responses, unfortunately my email, must be blocking the replies as I didn't get any notifications.
I've never used PowerShell so that would be another learning curve and JosefZ's post certainly will be reviewed.
I did some more intensive searching out of work hours and located a command based utility:
EditVar/EditV32/EditV64 and Choose/Choose32/Choose64
(C) 2006-2014 by Bill Stewart (bstewart#iname.com)
This resides in the same location as the orinal script and just requires a line to call it and assign a string, in the example below %PASSWORD% will be the string which I can then use in place of "*", works a treat.
editv64 -p "Enter your password: " PASSWORD -m
Good to get feed back and I'll be sorting my email filters out - Cheers.
A clone from my answer to another question:
Set /P "=Type the password for \\server\users\%UserName%:" < Nul
Call :PasswordInput serverpass
net use u: \\server\users\%UserName% %serverpass% /user:%UserName% /persistent:no
rem skip over the procedure
goto :eof
:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401.
::Set in variable Line a input password
::
::Update 20150503: https://stackoverflow.com/users/3439404/josefz?tab=profile
::Changes made in next lines:
:: SetLocal EnableDelayedExpansion
:: If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
::Usage:
:: Call :PasswordInput variableName
::where variableName is a name of output variable (by reference call)
::
SetLocal EnableDelayedExpansion
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
Set "Line=!Line:~0,-1!"
)
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd
Resources (required reading):
(command reference) An A-Z Index of the Windows CMD command line
(additional particularities) Windows CMD Shell Command Line Syntax
PowerShell sample script to read hidden input string and pass to multiple net use commands:
Function Read-Password {
param(
[String] $promptString
)
$secureString = Read-Host $promptString -AsSecureString
try {
$intPtr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($intPtr)
}
finally {
if ( $intPtr ) {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($intPtr)
}
}
$password
}
$password = Read-Password "Enter password"
if ( -not $password ) { return }
net use \\server1\share /user:foo $password
net use \\server2\share /user:foo $password
# ... etc.

Resources