Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. <#
  2. .Synopsis
  3. Script to import fileset onto BTLS supported SIMS servers. By AshG@BTLS
  4. .DESCRIPTION
  5. This is intended to be deployed with SCCM. In the package should be this and the required fileset (as a .zip). This script
  6. will attempt to gain the schoolnumber from the registry, machinename or the connect.ini path. It will then use this to
  7. extract the password for the westfield user, and then use these along with identified variables to run teh deployfileset.exe
  8. utility.
  9. The westfield user MUST have returns manager operator rights in order to perform this task.
  10. .EXAMPLE
  11. import-fileset -verbose
  12.  
  13. #>
  14.  
  15. Function import-fileset
  16. {
  17. [CmdletBinding()]
  18. param ([string] $fileset)
  19.  
  20. if (${env:ProgramFiles(x86)}){$deploypath = 'C:\Program Files (x86)\sims\SIMS .net\deployfileset.exe'} else {$deploypath = 'C:\Program Files\sims\SIMS .net\deployfileset.exe'}
  21.  
  22. $files = @("c:\shared\sims\connect.ini","d:\shared\sims\connect.ini")
  23. foreach ($file in $files)
  24. {
  25. $user = "westfield"
  26. if (test-path $file -ErrorAction SilentlyContinue)
  27. {
  28. $lines = gc $file
  29. foreach ($line in $lines)
  30. {
  31. if ( $line | select-string -pattern "servername")
  32. {
  33. $servername = $line.split("=")
  34. $var = "Server:"+$servername[1]
  35. write-verbose $var
  36. }
  37. if ( $line | select-string -pattern "databasename")
  38. {
  39. $db = $line.split("=")
  40. $var2 = "db:"+$db[1]
  41. write-verbose $var2
  42. }
  43. }
  44.  
  45. # check DM"
  46.  
  47. if (test-path "C:\Program Files (x86)\SIMS\SIMS .net Document Server\dmconfig.exe" -erroraction silentlycontinue ) {$dmconfig = "C:\Program Files (x86)\SIMS\SIMS .net Document Server\dmconfig.exe"}
  48. if (test-path "C:\Program Files\SIMS\SIMS .net Document Server\dmconfig.exe" -erroraction silentlycontinue ) {$dmconfig = "C:\Program Files\SIMS\SIMS .net Document Server\dmconfig.exe"}
  49. $result = & $dmconfig /T | select -last 1
  50. if ($result -eq "Server is running")
  51. {write-verbose "DmConfig responded OK"} else {write-verbose "DmConfig responded OK"}
  52. $key = "HKLM:\SOFTWARE\Westfield\Stationdetails"
  53.  
  54. # transpose schoolnumber
  55. $value = (get-itemproperty -path $key -Name SchoolID -ea silentlycontinue).SchoolID
  56. if ($value.Length -eq '5')
  57. {
  58. write-verbose "Schoolnumber identified as $value"
  59. } else {
  60. Write-Warning "Schoolnumber lookup failed"
  61. # look to see if first 5 digits of computername are numbers, and if so, try that.
  62. $var = $env:COMPUTERNAME
  63. $snip = $var.Substring(0,5)
  64.  
  65. # Not all schoolnumbers are numbers, but most are ...
  66. Add-type -AssemblyName microsoft.visualbasic
  67. if ([microsoft.visualbasic.information]::IsNumeric($snip) -eq $true)
  68. {
  69. Write-verbose "Found a number in the computername - valid number"
  70. $value = $snip
  71. }
  72. else
  73. {
  74. if ($snip.substring(0,2) -eq "LG")
  75. {
  76. write-verbose "Found a LG number in the computername - valid number"
  77. $value = $snip
  78. }else {
  79. write-verbose "Was not able to find a number in the registry or the servername."
  80. }
  81. }
  82. }
  83.  
  84. # Number found, now need to transpose
  85. $pw = @()
  86. if ($value)
  87. {
  88.  
  89. for ($test = 0; $test -lt 5; $test++)
  90. {
  91. $num = $value.Substring($test,1)
  92. $letter = [char](96 + $num)
  93. $pw+=$letter
  94. }
  95. $string =$pw[0]+$pw[1]+$pw[2]+$pw[3]+$pw[4]
  96. write-verbose "Transposed password is $string"
  97. $pwd = "west$string"
  98. write-verbose "full password is $pwd"
  99. }
  100.  
  101. write-verbose "removing btls_fileset directory on c:"
  102. remove-item -path c:\btls_fileset -force -recurse -ea silentlycontinue
  103.  
  104. write-verbose "Exporting .zip file"
  105. if(!$PSScriptRoot)
  106. { $location = get-location
  107. $PSScriptRoot = $location.path }
  108. $path = $PSscriptroot
  109. $zipfile = gci -path $path -filter *.zip
  110. $fullpath = join-path $path $zipfile
  111. unzip $fullpath c:\btls_fileset
  112.  
  113. $myfileset = gci -path c:\btls_fileset -filter *.mfs
  114. $fileset = join-path c:\btls_fileset $myfileset
  115.  
  116. # call command
  117. $myserver= $servername[1]
  118. $mydb=$db[1]
  119. write-verbose "Attempting with: /server=$myserver /database=$mydb /user=$user /password=$pwd /fileset=$fileset /debug /validate"
  120.  
  121. & $deploypath /server=$myserver /database=$mydb /user=$user /password=$pwd /fileset=$fileset /debug ; $deploycode = $lastexitcode
  122. if ($deploycode -eq '0')
  123. {
  124. write-verbose "Ran successfully"
  125. [System.Environment]::Exit(0)
  126. }else{
  127. write-verbose "Failed with errorcode $deploycode"
  128. [System.Environment]::Exit($deploycode)
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. }
  137. }
  138. }
  139.  
  140. function Unzip
  141. {
  142. param([string]$zipfile, [string]$outpath)
  143.  
  144. if ($PSVersionTable.PSVersion.Major -lt 5)
  145. {
  146. write-verbose "Less than powershell 5. Unpacking file manually"
  147. $shell = New-Object -ComObject shell.application
  148. $zip = $shell.NameSpace($zipfile)
  149. MkDir($outpath)
  150. foreach ($item in $zip.items())
  151. {
  152. $shell.Namespace($outpath).CopyHere($item)
  153. }
  154. }
  155. else
  156. {
  157. Add-Type -AssemblyName System.IO.Compression.FileSystem
  158. [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
  159. }
  160. }
  161.  
  162. #import-fileset -fileset 'C:\Users\Administrator\Desktop\1003-statutoryreturns-autumn2018_fileset\1003-StatutoryReturns-Autumn2018_Fileset.mfs' -verbose
  163. import-fileset -verbose
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement