How to fetch a xml file name via Custom inventory Rule
Hi
I want to read the file name as below and trim it using CIR.
File location C:\Program Files\IBM\Notes\Data
File name
CN=Greg Nixon_OU=MEL_OU=AUS_OU=APAC_O=COMPUTINGSolutions.xml
any commands to trim this file name ? i want to start the trim the file name from Greg Nixon till _ score CN=Greg Nixon_OU=MEL_OU=AUS_OU=APAC_O=COMPUTINGSolutions.xml
1 Comment
[ + ] Show comment
Answers (1)
Answer Summary:
Please log in to answer
Posted by:
flip1001
7 years ago
Top Answer
I tried these in a command prompt but using the echo command instead of dir since I don't have this program.
You may have to adjust the settings, and also I assume there is only 1 xml file in that directory.
cmd
for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files\IBM\Notes\Data\*.xml"') do set filename=%a && echo %filename:~3%
powershell
gci "C:\Program Files\IBM\Notes\Data\*.xml" | % {($_.name.split('_')[0]).substring(3)}
Comments:
-
thanks a lot for posting these.
\Program was unexpected at this time.
C:\>for /f "tokens=1 delims=_" \Program Files\IBM\Notes\Data\workspace\.metadat
a\.plugins\com.ibm.collaboration.realtime.login\*.xml"') do set filename=filenam
e:~3 - rahimpal 7 years ago -
gci "C:\Program Files\IBM\Notes\Data\*.xml" | % {($_.name.split('_')[0]).substring(3)}
this is perfect, but i want to try through batch commands as powershell success is not 100% in our network, also sometimes consumes CPU - rahimpal 7 years ago -
C:\Program Files\Dell\KACE>set filename=CN=Robert Chris && echo %filename:~3%
%filename:~3%
i get above output in CIR , how can i trim and output only Robert Chris ?
also how can i include
for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files\IBM\Notes\Data\*.xml"') do set filename=%a && echo %filename:~3%
or
for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files(X86)\IBM\Notes\Data\*.xml"') do set filename=%a && echo %filename:~3%
in same CIR - rahimpal 7 years ago-
Try this
ShellCommandTextReturn(cmd.exe /q /c if exist “C:\Program Files\IBM\Notes\Data\.” (for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files\IBM\Notes\Data\*.xml"') do set filename=%a && echo %filename:~3%) else (for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files(x86)\IBM\Notes\Data\*.xml"') do set filename=%a && echo %filename:~3%)) - flip1001 7 years ago-
thanks again..
i added this to CIR but i dont see any output in the inventory for x86 or 64 bit machines
ShellCommandTextReturn(cmd.exe /q /c if exist “C:\Program Files\IBM\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.login\.” (for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files\IBM\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.login\*.xml"') do set filename=%a && echo %filename:~3%) else (for /f "tokens=1 delims=_" %a in ('dir /b "C:\Program Files (x86)\IBM\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.login\*.xml"') do set filename=%a && echo %filename:~3%)) - rahimpal 7 years ago
this my command in bat file
======================================================================================================================
powershell.exe -nologo -Executionpolicy Bypass -WindowStyle Hidden -noprofile -file C:\ProgramData\Dell\KACE\downloads\33593\usernamefind.ps1
=======================================================================================================================
Powershell script
if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit")
{
#64 bit logic here
gci "C:\Program Files (x86)\IBM\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.login\*.xml" | % {($_.name.split('_')[0]).substring(3)} | Out-File C:\Windows\Temp\USERNAMES.txt -Force
}
else
{
#32 bit logic here
gci "C:\Program Files\IBM\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.login\*.xml" | % {($_.name.split('_')[0]).substring(3)} | Out-File C:\Windows\Temp\USERNAMES.txt -Force
} - rahimpal 7 years ago