I want to connect to a remote machine with psexec, use findstr to parse a file and save the needed record to a variable to be used later.
Here's c:\dir here\file.xml:
<Editable default="XXX07770004183" description="Station Id" name="MachineID.PSID" regex="^XXX[a-zA-Z0-9]{4}[0-9]{4}[a-zA-Z0-9]{3}$"/>
<Editable default="17" description="Machine Number" name="MachineID.MachineID" regex="^[0-9]+$"/>
<Editable default="32" description="Asset number" name="MachineID.AssetNumber" regex="^[0-9]+$"/>
<Editable default="AAALLL74" description="Serial number" name="MachineID.SerialNumber" regex="^[a-zA-Z0-9]+$"/>
If I connect to the remote machine manually and run the findstr below, it will report the correct value above: 32.
for /f tokens^=2^ delims^=^" %%a in ('findstr /C:"c:\dir here\file.xml') do set asset=%%a
echo %asset%
I'd like to loop these two together by having psexec connect to the machine, look in c:\dir here\file.xml and find the asset number and save it to a variable. For that matter, I should be able to save any of the fields in c:\dir here\file.xml to a variable.
What I have attempted:
@ECHO Off
SETLOCAL EnableDelayedExpansion
SET listT=list.txt
FOR /F %%A in ('TYPE "%listT%"') do (
bin\psexec -u registeredused -p secret \\%%A -s cmd /c findstr /C:"MachineID.AssetNumber" "c:\dir here\file.xml"
for /f tokens^=2^ delims^=^" %%b in ('findstr /C:"MachineID.AssetNumber" "c:\dir here\file.xml"') do set asset=%%b
echo %asset%
)
Result:
>find.cmd
PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd exited on 172.16.1.41 with error code 1.
ECHO is off.
So it can map a drive but basically fails beyond that.
I apologize for being so vague earlier.