Help creating a migration batch properly


  1. Posts : 4
    Buenos Aires
       #1

    Help creating a migration batch properly


    hello there my friends im in a migration process, and i need to create this batch properly

    what i need are 2 things:

    1) to this batch create a sub batch with mapped drives
    *so far where im stuck in, is in doing net use >> g:\%username%\migracion_vieja\mapped drives.txt
    *but idk how to do a batch file from that txt wich is telling me the path of the current mapped drives to import then from doing a bath file.

    2) to export connected networks printers into a txt


    this is my batch, is in spanish so im sorry in advance for that. basicly what is doing is exporting to a txt system info, like hostname, operative system name, domain, etc.

    @echo chequeando informacion pc vieja

    mkdir g:\%username%
    mkdir g:\%username%\migracion_vieja

    systeminfo | find /i "Nombre de host" >> g:\%username%\migracion_vieja\Nombre_De_Host_vieja.txt
    systeminfo | find /i "Nombre del sistema operativo" >> g:\%username%\migracion_vieja\Nombre_del_sistema_operativo_vieja.txt
    systeminfo | find /i "Dominio" >> g:\%username%\migracion_vieja\Dominio_vieja.txt
    systeminfo | find /i "Fabricante del sistema" >> g:\%username%\migracion_vieja\Fabricante_Del_Sistema_vieja.txt
    systeminfo | find /i "Modelo el sistema" >> g:\%username%\migracion_vieja\Modelo_Del_Sistema_vieja.txt
    systeminfo | find /i "Tipo de sistema" >> g:\%username%\migracion_vieja\Tipo_De_Sistema_vieja.txt
    ipconfig >> g:\%username%\migracion_vieja\ip_vieja.txt

    @echo Completeda migración vieja!

    thanks in advance and forgive for my english if is not clearly what i need =)

    Best regards jonathan
    Last edited by darthmalakit; 05 Oct 2019 at 14:13.
      My Computer


  2. Posts : 7,351
    Windows 7 HP 64
       #2

    Buenas tardes hermano.

    What you want to achieve?
    From where you want to migrate? to where?
      My Computers


  3. Posts : 4
    Buenos Aires
    Thread Starter
       #3

    hello im doing a migration. / hola estoy haciendo una migracion

    I have to take from the old pc all the info,including domain, host name etc, as well as mapped drives and mapped em into a new pc. as well as connected network printers export ´em into a txt / tengo que tomar los datos de la pc vieja, eso incluye dominio, nombre de host, etc y necesito en el batch que estoy haciendo, que el mismo cree un batch con las unidades de red conectadas y exportar a un txt las impresoras de red conectas.

    so far this is what im doing / hasta ahora esto es lo que pude hacer

    @echo chequeando informacion pc vieja

    mkdir g:\%username%
    mkdir g:\%username%\migracion_vieja

    systeminfo | find /i "Nombre de host" >> g:\%username%\migracion_vieja\Nombre_De_Host_vieja.txt
    systeminfo | find /i "Nombre del sistema operativo" >> g:\%username%\migracion_vieja\Nombre_del_sistema_operativo_vieja.txt
    systeminfo | find /i "Dominio" >> g:\%username%\migracion_vieja\Dominio_vieja.txt
    systeminfo | find /i "Fabricante del sistema" >> g:\%username%\migracion_vieja\Fabricante_Del_Sistema_vieja.txt
    systeminfo | find /i "Modelo el sistema" >> g:\%username%\migracion_vieja\Modelo_Del_Sistema_vieja.txt
    systeminfo | find /i "Tipo de sistema" >> g:\%username%\migracion_vieja\Tipo_De_Sistema_vieja.txt
    ipconfig >> g:\%username%\migracion_vieja\ip_vieja.txt
    @echo Completeda migración vieja!

    *so far where im stuck in, is in doing net use >> g:\%username%\migracion_vieja\mapped drives.txt / por ahora en donde estoy trabado es haciendo un net use y exportando eso a un txt
    *but idk how to do a batch file from that txt wich is telling me the path of the current mapped drives to import then from doing a bath file. / pero no se como hacer un batch de ese txt que me esta diciendo la direccion de las unidades de red conectadas, para poder importarlas desde un batch a una nueva pc.

    2) to export connected networks printers into a txt / exportar impresoras de red conectadas a un txt.
      My Computer


  4. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #4

    Hi darthmalakit,

    Welcome to SevenForums!

    I don't speak Spanish but I can see that you are using systeminfo!
    You may also want to look at wmic.

    As an example . . .

    Code:
    For /f "tokens=2 delims='='" %%A In ('wmic NETLOGIN Get HomeDirectory /value') Do Set HomeDirectory=%%A
    I hope this helps!
      My Computer


  5. Posts : 4
    Buenos Aires
    Thread Starter
       #5

    Paul Black said:
    Hi darthmalakit,

    Welcome to SevenForums!

    I don't speak Spanish but I can see that you are using systeminfo!
    You may also want to look at wmic.

    As an example . . .

    Code:
    For /f "tokens=2 delims='='" %%A In ('wmic NETLOGIN Get HomeDirectory /value') Do Set HomeDirectory=%%A
    I hope this helps!
    thank u for u reply. I dont know what that command does.

    a) What im needing is ,to be as much as clarifing as possible is : from old pc, take current mapped drives export em into a batch from those current mapped drives from %username%, and then in the new pc. Just click on that batch and map those drives from old pc to new one again.

    b) to export to a txt file, current path of %username% mapped printers. to then manually map those printers again (wich they arent local)
    exampe \\sfs-1\printer name
    From there i can put that into run command.

    Yes, what im doing in the migration process, is taking systeminfo that i need, from the old pc, and the new one, and in order to improve the current process i need to made a batch from current map drives fold old pc, and import em with that batch to new one, as well as mapped printers
      My Computer


  6. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #6

    Hi darthmalakit,

    Have you tried . . .

    [1] net use [command line]?
    [2] To output the file to the desktop for a list of the current mapped drives for the current user and current connection try this . . .

    net use > "%userprofile%\Desktop\Mapped_Drives.txt"

    Is this the sort of thing you are looking for?
      My Computer


  7. Posts : 4
    Buenos Aires
    Thread Starter
       #7

    Paul Black said:
    Hi darthmalakit,

    Have you tried . . .

    [1] net use [command line]?
    [2] To output the file to the desktop for a list of the current mapped drives for the current user and current connection try this . . .

    net use > "%userprofile%\Desktop\Mapped_Drives.txt"

    Is this the sort of thing you are looking for?
    From there is where im stuck

    current command lines is:

    net use | find "slash slash" > d:\mapped_drives.txt

    that gives into result as just using as example of my current mapped drives, just for testing

    Conected W: \\192.168.1.XXX\Volume_2 Microsoft Windows Network

    in order to clean that i did a powershell command line wich do this:

    $drivelist = (Get-Content C:\prueba\drivelist.txt | Select-String -Pattern "") | Out-String
    $drivelist = $drivelist -replace("Conected","")
    $drivelist = $drivelist -replace("Microsoft Windows Network","")
    $drivelist = $drivelist -replace(" ","")
    $drivelist = $drivelist -replace(':\\',': \')
    $drivelist | Out-File C:\prueba\drivelist2.txt

    foreach ($line in [System.IO.File]::ReadLines("C:\prueba\drivelist2.txt")) {
    $parts = $line.split(" ")
    net use $parts[0] $parts[1]
    }

    wich give the clean path

    W: \\192.168.1.XXX\Volume_2

    then i did

    cls
    #Define Functions
    (gc G:\migracion_vieja\unidades_de_red_limpio.txt) -replace '\S+$','$& /persistent:yes' | out-file "G:\preparando.txt"

    wich adds /persistent yes to the end of each line

    then i did

    $Lines = Get-Content .\preparando.txt
    $OutputPath = "g:\discos_mapeados.bat"
    foreach ($Line in $Lines) {
    $Line = $line.Insert(0,'net use ')
    $Line += ''
    Write-Output $Line | Out-File $OutputPath -Append

    Wich add net use to the begginig of each line and create the batch file

    thats what i wanted. thank u
    Last edited by darthmalakit; 08 Oct 2019 at 20:19.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:43.
Find Us