Copy files to a workstation using a compliance setting

There’s more than 1 way to solve a problem, and this is a perfect example.
The issue at hand: we want to distribute a common set of files to all workstations, and make sure they always have the latest version.
We could use a login or startup script, but in this case the AD guys don’t want it as another maintenance task.
so we have a couple more solutions: (1) set up a scheduled task, using SCCM to deploy the task to all workstations.
(2) Setup an SCCM compliance, using Powershell or VBscript to copy the files.
Regardless the method, we’re running as the system account, so we need to run as a service account to access the network. Turns out this runs fine without a service account, so I simplified the script. Yay!

Here’s the solution, using an SCCM compliance setting. Look elsewhere on this site forĀ  the Task Scheduler solution (not yet posted)

[VBscript code]
Option Explicit
' DownloadOCTADatabaseControlFiles.VBS v.
'   Purpose: copy database control files from network location to local drive (current folder)
'Deployment: Run as an SCCM Compliance setting
'    Author: Roger C 8/4/2017

dim SourceShare: SourceShare = "\\Server\Share"
dim SourcePath: SourcePath= SourceShare & "\ORAFILES"
dim TNSPath: TNSPath="C:\Oracle\product\network\admin"
dim File1: File1="SQLNET.ORA"
dim File2: File2="TNSNAMES.ORA"
dim Success : Success = "Success"
dim Failure : Failure = "Failed"

Dim objFSO     
dim objShell

' Connect to the local drive
on error resume next 
Set objFSO = CreateObject("scripting.FileSystemObject")
on error goto 0
If not IsObject(objFSO) then wscript.echo "Failed" : wscript.quit 1

' connect to a shell
on error resume next 
Set objShell = WScript.CreateObject ("WScript.Shell")
on error goto 0
If not IsObject(objShell) then wscript.echo "Failed" : wscript.quit 1

' set the system environment variable "cmd /c SETX /M TNS_ADMIN %TNSPath% | out-null"

' create the local path if it doesn't exist
If not(objFSO.FolderExists("C:\Oracle"                      )) THEN objFSO.CreateFolder("C:\Oracle"                      )
If not(objFSO.FolderExists("C:\Oracle\product"              )) THEN objFSO.CreateFolder("C:\Oracle\product"              )
If not(objFSO.FolderExists("C:\Oracle\product\network"      )) THEN objFSO.CreateFolder("C:\Oracle\product\network"      )
If not(objFSO.FolderExists("C:\Oracle\product\network\admin")) THEN objFSO.CreateFolder("C:\Oracle\product\network\admin")

if ProcessFile(File1) and ProcessFile(File2) then
	Wscript.echo Success
	Wscript.echo Failure
	Wscript.quit 1
end if 

Set objShell = Nothing
set objFSO = Nothing

Function ProcessFile(F)
	Dim F1 : F1 = SourcePath & "\" & F
	Dim F2 : F2 = TNSPath & "\" & F
	If not (objFSO.FileExists(F1)) then ProcessFile =  VBFalse : Exit Function ' error if source file is missing
	objFSO.CopyFile F1, F2 'copy the source file to destination file
	if ("fc.exe " & F1 & " " & F2, 2, VBTrue) then ProcessFile =  VBFalse : Exit Function ' error if source does not match destination
	ProcessFile = VBTrue
end function

$SourceShare = "\\server\share"
$SourcePath=$SourceShare + "\ORAFILES"
net use $SourceShare "PasswordGoesHere" /USER:domain\username | out-null
SETX /M TNS_ADMIN %TNSPath% | out-null
if (-not (Test-Path $TNSPath)) {md $TNSPath}
foreach ($F in $file1, $File2) {
    if (Test-Path $SourcePath+"\"+$F) {
        Exit 1
    Copy-Item "$SourcePath\$f" "$TNSPath\$F"
    if (Compare-Object (get-content "$SourcePath\$F") (get-content "$TNSPath\$F") -SyncWindow 0) {
        Exit 1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s