Announcement

Collapse
No announcement yet.

Xcopy - Invalid number of parameters

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Xcopy - Invalid number of parameters

    Can anyone help with this one?

    Iím trying to copy the Group Policy folders from my USB memory stick to a laptop. This will update the GPO with a batch file rather than manually copying the folders over.


    I have the USB drive mapped as the Z: drive on the laptop.
    The GPO folders I need to copy are on the USB drive in the following location:

    Z:\Advisor GPO\GPO Enabled\Machine
    Z:\Advisor GPO\GPO Enabled\User

    I need to copy both folders to:

    %SystemRoot%\system32\GroupPolicy

    My scrip is as follows:

    xcopy Z:\Advisor GPO\GPO Enabled\Machine\* %SYSTEMROOT%\system32\GroupPolicy /e /v /c /i /h /r /y
    xcopy Z:\Advisor GPO\GPO Enabled\User\* %SYSTEMROOT%\system32\GroupPolicy /e /v /c /i /h /r /y
    gpupdate /force


    When I run the script I see "Invalid Number of parameters". So I tried running this instead:

    xcopy Z:\Advisor GPO\GPO Enabled\Machine\* %SYSTEMROOT%\system32\GroupPolicy

    I still see the same error, what am I doing wrong??


    .

  • #2
    Re: Xcopy - Invalid number of parameters

    The source paths contain spaces therefore you have to use quote-signs around the path.
    The path Z:\Advisor GPO\GPO Enabled\Machine\* should be written like "Z:\Advisor GPO\GPO Enabled\Machine\*"
    (or, when the batch file is on Z: use the path of the batchfile (%~dp0) exented with the subfolders you like to copy: "%~dp0Advisor GPO\GPO Enabled\Machine\*" )

    Is OK if you put all paths between quotes also: "%SYSTEMROOT%\system32\GroupPolicy\"


    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Xcopy - Invalid number of parameters

      As simple as that then, just needed the quotations.

      The script works a treat but it doesnt seam to be updating the GPO now, any ideas why?

      I can still do this manually & it works


      Also not sure what you mean by (%~dp0)

      Comment


      • #4
        Re: Xcopy - Invalid number of parameters

        Had a few problems getting this to work but a bit of perseverance won out in this case. Here what the wining scripts were:

        GPO Enable
        xcopy "Z:\AdvisorGPO\GPOEnabled\Machine\*" %SYSTEMROOT%\system32\GroupPolicy\Machine /e /v /c /i /h /r /y
        xcopy "Z:\AdvisorGPO\GPOEnabled\User\*" %SYSTEMROOT%\system32\GroupPolicy\User /e /v /c /i /h /r /y
        gpupdate /force


        GPO Disable
        xcopy "Z:\AdvisorGPO\GPODisabled\Machine\*" %SYSTEMROOT%\system32\GroupPolicy\Machine /e /v /c /i /h /r /y
        xcopy "Z:\AdvisorGPO\GPODisabled\User\*" %SYSTEMROOT%\system32\GroupPolicy\User /e /v /c /i /h /r /y
        gpupdate /force


        Thanks again for the help


        .

        Comment


        • #5
          Re: Xcopy - Invalid number of parameters

          FWIW I've recently updated all of our scripts that used to use xcopy to use robocopy, which is much easier to configure, much more robust and has a lot more options. It's native in Vista/Server 2008 and part of the 2K3 resource kit. Well worth a look.
          BSc, MCSA: Server 2008, MCSE, MCSA: Messaging, MCTS
          sigpic
          Cruachan's Blog

          Comment


          • #6
            Re: Xcopy - Invalid number of parameters

            Glad you got it sorted.


            \Rems



            Originally posted by Deland01 View Post
            not sure what you mean by (%~dp0)
            The variable %0 is by default the program name as it was called. It can expand in the batch the path from were the batch is executed including the batchfile name (http://www.robvanderwoude.com/parameters.php). Furthermore, you can use variable modifiers on %0 to expand only the drive letter or path to the batchfile.

            When you use the %0 with the modifiers ~dp it is entered like: %~dp0 Using this in your batch it will echo the location of the batch.
            So if the batch is on the same usb-device as the folders and files you want to copy, you can use the location of the batch (or just expand the drive letter when you use: %~d0 ) as a starting point for the location of the source folders that you want to copy to the computer for the XCOPY command.
            This way you do not need to worry about the usb-drive is explicitly assigned the drive letter Z: on every computer on were you run this batch.

            The following samples batch can show you what I mean,
            Code:
            @echo off
            Set "percentsignZero=%%0" (this variable is just used for descriptions echoed before each sample in this batch)
            
            
            echo The variable %percentsignZero% is the program name as it was called.
            echo It will expand the path including the batchfile name.
            
            echo/&rem -=sample=-
            echo.  Expanding the variable %percentsignZero%
            echo.  %0
            
            echo/
            echo/
            :: http://www.robvanderwoude.com/parameters.php
            echo Substitution of Batch-Parameter and FOR variable references has been enhanced.
            echo You can use the following variable modifiers when is it for existing files.
            echo The available modifiers are:
            
            echo/&rem -=sample=-
            echo. 1.The modifier ~ expand %percentsignZero% but it removes any surrounding quotes
            echo.   %~0
            
            echo/&rem -=sample=-
            echo. 2.The modifier ~f can expand %percentsignZero% to a fully qualified path name
            echo.   %~f0
            
            echo/&rem -=sample=-
            echo. 3.The modifier ~p can expand %percentsignZero% to a path only (without the driveletter)
            echo.   %~p0
            
            echo/&rem -=sample=-
            echo. 4.The modifier ~d can expand %percentsignZero% to a drive letter only
            echo.   %~d0
            
            echo/&rem -=sample=-
            echo. 5.The modifier ~n can expand %percentsignZero% to a file name only (without the extension)
            echo.   %~n0
            
            echo/&rem -=sample=-
            echo. 6.The modifier ~x can expand %percentsignZero% to a file extension only
            echo.   %~x0
            
            echo/&rem -=sample=-
            echo. 7.The modifier ~s can expand %percentsignZero% to a path contains short names
            echo.   %~s0
            
            echo/&rem -=sample=-
            echo. 8.Extra modifiers ~a ~t and ~z can expand resectively,
            echo.   the file attributes  : %~a0 bits
            echo.   datetime lastmodified: %~t0
            echo.   size of file         : %~z0  bytes
            
            echo/
            echo/
            echo The modifiers can be combined (in the desired order) to get compound results:
            
            echo/&rem -=sample=-
            echo. * The modifiers ~dp expands the drive letter and path
            echo.   %~dp0
            
            echo/&rem -=sample=-
            echo. * The modifiers ~nx expands file name and extension
            echo.   %~nx0
            
            echo/&rem -=sample=-
            echo. * The combined modifiers ~fs expands the full path name with short names
            echo.   %~fs0
            
            echo/
            echo/
            :: Alternative of using the modifier combination ~dp
            :: see http://support.microsoft.com/kb/121387 (i.e. Dir/p %0\..\"subfolder\filename" )
            pause

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Xcopy - Invalid number of parameters

              Rems - I looked all over the net for a way how to do this but wasnít really sure what to look for. Imp not a programmer and this looks like it might take me a while to figure out but I'll defiantly have a bash.

              cruachan - would this work on XP Pro without having to install the resource pack first?

              Comment

              Working...
              X