SCCM 2012 to distribute files (not application) - sccm

I want to use SCCM 2012 to distribute some files (not application, no executable there).
I know there is a way to create a batch file with xcopy command, and create a package to deploy that batch file to the clients. However, if I use xcopy I cannot leverage the BITS functionality and other benefits from SCCM.
Is this possible?

Hi I can see this is an old post, but I have used SCCM to copy files in the past.
A company I worked for in the past refused to use GP for any file copy (don't get me started) so I had to implement GP files over SCCM.
Here are some examples I used.
xcopy User.bmp "%ProgramData%\Microsoft\User Account Pictures" /c /y /r
REG ADD HKLM\Software\FILE_GP /v Copy_User_image /t REG_sz /d 1.0 /f
timeout 5
if not exist "%windir%\system32\oobe\Info\backgrounds" md "%windir%\system32\oobe\Info\backgrounds"
xcopy backgrounddefault.jpg "%windir%\system32\oobe\Info\backgrounds" /c /y /r
REG ADD HKLM\Software\File_GP /v Backgrounddefault /t REG_sz /d 1.0 /f
timeout 5
I had the script add the Registry key so I could use Application deployment and have the detection method look for the key as well as the file. So if a user deleted the file it would return.
The main reason for me to have the Reg Key was if you wanted to push an updated version of the file I could set the new copy script to push 1.1 to the reg key and have the detection look for that version, then I could retire the 1.0 version.
I found also for short scripts of 1 file of small size without the timeout line it would report failed immediately, if there were larger files I didn't need the timeout. The initial fail does clear after some time without the timeout line.

It should work if you chose your settings right.
In your batch make sure that all the paths and references are relative and never absolute.
Then when you create the deployment there is a point called "Distribution Points" where you can select the deployment options for fast as well as unreliable networks. There you would have to choose "Download content from distribution point and run locally" in both cases. Then your batch would basically copy the files from the CCM cache to the hard drive.
This method should work for packages, for applications I think it would be more difficult because you cannot directly specify deployment options for fast networks there.

Packages are downloaded to the clients with BITS by default. The XCOPY command would copy from CCMCACHE to final destination on the machine.

Not sure if you have tried it or not but if you have deployed any .exe file for application its ask for dependence file in that you mention your required file which need to copy and create a script to copy data from ccmcache to copy the data to destination folder. for this you can get the use of BITS and to check if the file are copied or not you can use a proper detection method.

I used a PowerShell script for this purpose and it works like charm.
Create a new script and change this one liner to your mods:
Copy-Item -Path "\\[NETWORK PATH]" -Destination "[DESTINATION PATH]" -Recurse
Other way around—if need to make a required package—could be to create a new application deployment and run this through PowerShell (ExecutionPolicy ByPass) and manually install from the client side; if you don't want user interaction, make it a required deploy.

Related

Move a specific file from one folder to another on Windows 10 in specific periods by using script

I know I can use the below code to move all files from a source folder to a destination folder but how would I do this within a specific period of time. For example, I want to copy files from a folder into another folder every day at 2:00am. How can I do this with a script?
echo off
set X=<days>
set "source=C:\<Source Folder Path>"
set "destination=D:\<Destination Folder Path>"
robocopy "%source%" "%destination%" /mov /minage:%X%
exit /b
In case you want to do something periodically in Windows, using a script, I would give you following advise:
Write a script which does what you need to do.
Configure task scheduler to run the frequency and time table of your choice: adding this to the script itself is not a good idea (imagine you restart your computer and you have forgotten to re-launch your script, then it won't be executed again).

Copy files from One Server to Another Server using Batch Command - Windows machine

How to copy files from one server to another server(VM) using a windows batch command. ?
I have used below command
syntax : xcopy \\source_path \\serverIP\Destination_path /s /a /d
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
I'm getting the below error "Invalid drive specification" as of now.
Do I need to give credentials for accessing the VM ? If yes then where and how?
I have checked the destination path is correct.
Is there any other command should be used in that case ?
Do I need to give credentials for accessing the VM ? If yes then where and how?
If the passwords on the source and target machine are the same then no credentials are necessary, otherwise yes they will need to be provided. Two solutions you can consider:
Use "runas" and specify the credentials there
Use the temporary network drive solution proposed in the comment by UserPo41085. This solution uses the "net view" command which has credential parms.
I have checked the destination path is correct.
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
Both paths in the example provided are a mixture of standard "DOS" paths and UNC paths. UNC paths reference a share name and not a disk letter.
The example in the link below copies a file on the local machine called zz_yuv.png to a machine called "ws9" which has a share called "c9.system" and the share is mapped to the root folder of the c: drive on ws9. If you are running an account which is a member of the administrators group you can use the admin shares...(admin$, c$ etc.)
xcopy example
Is there any other command should be used in that case ?
Robocopy is built into the later versions of windows. It does come with a learning curve but is much more robust than xcopy. Just as a note, robocopy will be under the same types of credentialing restraints as xcopy - it just has more and better features for copying.

Batch file - IF EXISTS statement "The system cannot open the device or file specified."

I have written a batch file to uninstall a faulty WiFi driver (Intel ProSet Wireless) and set up the appropriate wireless profile on a laptop. This script is intended to be run remotely through Symantec Management Agent.
The code starts by running a group policy update to pull down appropriate
network certificates from the server. Then the code checks to see if the WiFi driver is installed. If it is, the script uninstalls it. Afterwards, in either case, it will wipe the current wireless profiles and call another batch file to install the appropriate wireless profile.
My issue is, when I run the script, the console will report "The system cannot open the device or file specified." after the software is uninstalled and it will terminate. The IF EXIST statement checks to see if one of the software files is there.
Typically, I can just run the same script a second time, and the IF EXIST case will not be met, so the rest of the batch file will work properly.
I am attaching my code below -- am I using IF EXIST correctly?
gpupdate /force
IF EXIST "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\setup.exe" (
cd "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\"
start /wait setup.exe /uninstall
)
TIMEOUT /T 3 /nobreak >nul
netsh wlan delete profile name=*
cd "C:\Wireless_Settings\"
Mobile_Devices_profile.bat
I have researched other posts, and I do believe I am using the condition correctly. I don't see any other post that matches my case. It always correctly checks to see if the condition is met, however I don't understand why the program terminates after the software is uninstalled. All that I believe should happen is the case is no longer met, so the script continues on.
Possible solution : (your if statement appears to be correct)
Insert a pushd statement before the cd and a popd after the start.
This will ensure you return to your original directory after the if statement invokes setup.exe
IF EXIST "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\setup.exe" (
PUSHD
cd "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\"
start /wait setup.exe /uninstall
POPD
)
If it works, fine and good. If it doesn't, It's easy to undo.
Sure - in theory, you could change the cd to a PUSHD instead. There are many paths.
IF EXIST "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\setup.exe" (
PUSHD "C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\"
start /wait setup.exe /uninstall
POPD
)
This should work.
Now that's interesting. I'm sure I've use pushd without arguments before. The documentation reads
Stores the current directory for use by the POPD command, then
changes to the specified directory.
PUSHD [path | ..]
which is not explicit when the option argument is missing.
I've also noticed that a dir list on my batch-development directory now lists a unicode-named file with spaces between the squares whereas it used to not contain those spaces. Maybe something has been silently changed... cmd version is dated 20170929
Setup.exe is trying to remove the directory from the Package Cache which happens to be your current working directory. Not a good way for a script to live.
#setlocal ENABLEEXTENSIONS
#rem #set prompt=$G
#set "_setupExe=C:\ProgramData\Package Cache\{552523b2-40ad-46b3-94f6-2b99d0860d5c}\setup.exe"
#gpupdate /force
#if exist "%_setupExe%" call %_setupExe% /uninstall
#TIMEOUT /T 3 /nobreak >nul
#netsh wlan delete profile name=*
#cd "C:\Wireless_Settings\"
#Mobile_Devices_profile.bat
I would add that debugging your script was complicated by the fact that you had a multi-line code block. You should avoid those at all costs. It's better to call a subroutine if you can fit it all on a single line.

A script to automatically delete folders in another folder

I've came across several posts and even code online about .batch files to delete folders and files. However, I am still pretty confused by the myriad amount of information that's on the Internet. Is there a specific way of writing a script that automatically deletes folders that are older than 30 days (the script has to be smart enough to run itself and not be done manually)
I appreciate your help and I am willing to learn here. Thanks!
P.S. I've attached an example of the kind of folders that I would like to delete. As you can see these folders date back to 2008
This will remove the entire directory tree, so use it with coution and remove the echo, if the output is OK:
forfiles /d -30 /c "cmd /c if #isdir==TRUE echo rd /s /q #fname"
Scripts can not run them selves automatically, but the os provides facilities to do that using scheduled tasks. So you need to create yourself a batch file to delete what you need and then add a recurring scheduled task to do the work.
There is no built-in batch command to work only on files with a certain age. But you can download the forfiles tool from Microsoft. It allows to execute commands on files of a certain age only (on the command line).

Batch file to copy files from one directory to another

I have two code bases of an application. I need to copy all the files in all the directories with .java from the newer code base, to the older (so I can commit it to svn).
How can I write a batch files to do this?
XCOPY /D ?
xcopy c:\olddir\*.java c:\newdir /D /E /Q /Y
If you've lots of different instances of this problem to solve, I've had some success with Apache Ant for this kind of copy/update/backup kind of thing.
There is a bit of a learning curve, though, and it does require you to have a Java runtime environment installed.
I like Robocopy ("Robust File Copy"). It is a command-line directory replication command. It was available as part of the Windows Resource Kit, and is introduced as a standard feature of Windows Vista and Windows Server 2008.

Resources