|
|
|||||||
Hi Guys, I'm trying to write a script to copy files to a group of servers. I apologize if there already is a UDF for this, but the proxy server here at work apparently renders the UDF list as blank. I have a group of Windows 2008 R2 servers. I have placed the files in c:\temp. I also have two ini files in the same location. One has a list of all the computers in the local group and the other has a list of the files to be copied. Examples: computers.ini Code: [computers] comp1=server-name1 comp2=server-name2 comp3=another-server files.ini Code: [Files] file1=jdk-6u35-windows-i586.exe file2=visioviewer.exe I'm trying to use: Code: Break On Dim $SO $SO = SetOption('Explicit', 'On') $SO = SetOption('NoMacrosInStrings', 'On') Dim $strWks, $strFile, $colFiletoSend Dim $strComps, $colComps, $objComp, $objFSO Dim $intErr, $objFile, $strFileName, $strRemotePath $strFile = "c:\temp\files.ini" $strComps = "c:\temp\computers.ini" $colComps = Split(ReadProfileString($strComps,"computers",""),chr(10)) For each $objComp in $colComps If $objComp <> "" $strWks = ReadProfileString(strComps,"computers",$objComp) $colFiletoSend = Split(ReadProfileString($strFile,"Files",""),chr(10)) cd "c:\temp" $strRemotePath = "\\" + $strWks + "\c$\temp" $objFSO = CreateObject("Scripting.FileSystemObject) For each $objFile in $colFiletoSend If $objFile <> "" $strFileName = ReadProfileString($strFile,"Files",$objFile) $intErr = $objFSO.CopyFile($strFileName,$strRemotePath) EndIF Next EndIf Next When attempting the copy, I'm getting: Code: COM exception error "CopyFile" <<null> - <null>> [-2147352567/80020009] If I just do from a command prompt in c:\temp: Code: copy jdk-6u35-windows-i586.exe \\server-name1\c$\temp Thanks |
||||||||
|
|
|||||||
Have you tried just using the built in kix version of COPY rather than the FSO com object? |
||||||||
|
|
|||||||
Also...This line has a typo (missing a $) Code: $strWks = ReadProfileString(strComps,"computers",$objComp) Should be... Code: $strWks = ReadProfileString($strComps,"computers",$objComp) |
||||||||
|
|
|||||||
I'll give that a try tomorrow. It's been a while and the manual didn't say I could use copy to copy to a remote system. (missing $ was just a typo - I can't cut and paste; everything has to be re-typed) |
||||||||
|
|
|||||||
This seemed to work ok for me. Code: Break On $strFile = "c:\temp\files.ini" $strComps = "c:\temp\computers.ini" $colComps = Split(ReadProfileString($strComps,"computers",""),chr(10)) For each $objComp in $colComps If $objComp <> "" $strWks = ReadProfileString($strComps,"computers",$objComp) $colFiletoSend = Split(ReadProfileString($strFile,"Files",""),chr(10)) $strRemotePath = "\\" + $strWks + "\c$\temp" For each $objFile in $colFiletoSend If $objFile <> "" $strFileName = "C:\Temp\"+ReadProfileString($strFile,"Files",$objFile) Copy $strFileName $strRemotePath EndIF Next EndIf Next |
||||||||
|
|
|||||||
Oh and make sure to turn on NOVARSINSTRINGS as well. The dollar sign in the share path might be giving you problems. I just tested to a non-hidden \\server\share type directory and it worked fine. |
||||||||
|
|
|||||||
Shane appears to hard code the paths whereas BradV infers from current working directory. I see a CD but the current working drive might be different. |
||||||||
|
|
|||||||
Oh yes, forgot to mention that one. |
||||||||
|
|
|||||||
Yes, I kept the cd in. Worked perfectly. Maybe we should suggest a change to the manual to add that copy to a remote system also works? Thanks Shane! |