Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Synopsis
- Script to import fileset onto BTLS supported SIMS servers. By AshG@BTLS
- .DESCRIPTION
- This is intended to be deployed with SCCM. In the package should be this and the required fileset (as a .zip). This script
- will attempt to gain the schoolnumber from the registry, machinename or the connect.ini path. It will then use this to
- extract the password for the westfield user, and then use these along with identified variables to run teh deployfileset.exe
- utility.
- The westfield user MUST have returns manager operator rights in order to perform this task.
- .EXAMPLE
- import-fileset -verbose
- #>
- Function import-fileset
- {
- [CmdletBinding()]
- param ([string] $fileset)
- if (${env:ProgramFiles(x86)}){$deploypath = 'C:\Program Files (x86)\sims\SIMS .net\deployfileset.exe'} else {$deploypath = 'C:\Program Files\sims\SIMS .net\deployfileset.exe'}
- $files = @("c:\shared\sims\connect.ini","d:\shared\sims\connect.ini")
- foreach ($file in $files)
- {
- $user = "westfield"
- if (test-path $file -ErrorAction SilentlyContinue)
- {
- $lines = gc $file
- foreach ($line in $lines)
- {
- if ( $line | select-string -pattern "servername")
- {
- $servername = $line.split("=")
- $var = "Server:"+$servername[1]
- write-verbose $var
- }
- if ( $line | select-string -pattern "databasename")
- {
- $db = $line.split("=")
- $var2 = "db:"+$db[1]
- write-verbose $var2
- }
- }
- # check DM"
- 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"}
- 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"}
- $result = & $dmconfig /T | select -last 1
- if ($result -eq "Server is running")
- {write-verbose "DmConfig responded OK"} else {write-verbose "DmConfig responded OK"}
- $key = "HKLM:\SOFTWARE\Westfield\Stationdetails"
- # transpose schoolnumber
- $value = (get-itemproperty -path $key -Name SchoolID -ea silentlycontinue).SchoolID
- if ($value.Length -eq '5')
- {
- write-verbose "Schoolnumber identified as $value"
- } else {
- Write-Warning "Schoolnumber lookup failed"
- # look to see if first 5 digits of computername are numbers, and if so, try that.
- $var = $env:COMPUTERNAME
- $snip = $var.Substring(0,5)
- # Not all schoolnumbers are numbers, but most are ...
- Add-type -AssemblyName microsoft.visualbasic
- if ([microsoft.visualbasic.information]::IsNumeric($snip) -eq $true)
- {
- Write-verbose "Found a number in the computername - valid number"
- $value = $snip
- }
- else
- {
- if ($snip.substring(0,2) -eq "LG")
- {
- write-verbose "Found a LG number in the computername - valid number"
- $value = $snip
- }else {
- write-verbose "Was not able to find a number in the registry or the servername."
- }
- }
- }
- # Number found, now need to transpose
- $pw = @()
- if ($value)
- {
- for ($test = 0; $test -lt 5; $test++)
- {
- $num = $value.Substring($test,1)
- $letter = [char](96 + $num)
- $pw+=$letter
- }
- $string =$pw[0]+$pw[1]+$pw[2]+$pw[3]+$pw[4]
- write-verbose "Transposed password is $string"
- $pwd = "west$string"
- write-verbose "full password is $pwd"
- }
- write-verbose "removing btls_fileset directory on c:"
- remove-item -path c:\btls_fileset -force -recurse -ea silentlycontinue
- write-verbose "Exporting .zip file"
- if(!$PSScriptRoot)
- { $location = get-location
- $PSScriptRoot = $location.path }
- $path = $PSscriptroot
- $zipfile = gci -path $path -filter *.zip
- $fullpath = join-path $path $zipfile
- unzip $fullpath c:\btls_fileset
- $myfileset = gci -path c:\btls_fileset -filter *.mfs
- $fileset = join-path c:\btls_fileset $myfileset
- # call command
- $myserver= $servername[1]
- $mydb=$db[1]
- write-verbose "Attempting with: /server=$myserver /database=$mydb /user=$user /password=$pwd /fileset=$fileset /debug /validate"
- & $deploypath /server=$myserver /database=$mydb /user=$user /password=$pwd /fileset=$fileset /debug ; $deploycode = $lastexitcode
- if ($deploycode -eq '0')
- {
- write-verbose "Ran successfully"
- [System.Environment]::Exit(0)
- }else{
- write-verbose "Failed with errorcode $deploycode"
- [System.Environment]::Exit($deploycode)
- }
- }
- }
- }
- function Unzip
- {
- param([string]$zipfile, [string]$outpath)
- if ($PSVersionTable.PSVersion.Major -lt 5)
- {
- write-verbose "Less than powershell 5. Unpacking file manually"
- $shell = New-Object -ComObject shell.application
- $zip = $shell.NameSpace($zipfile)
- MkDir($outpath)
- foreach ($item in $zip.items())
- {
- $shell.Namespace($outpath).CopyHere($item)
- }
- }
- else
- {
- Add-Type -AssemblyName System.IO.Compression.FileSystem
- [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
- }
- }
- #import-fileset -fileset 'C:\Users\Administrator\Desktop\1003-statutoryreturns-autumn2018_fileset\1003-StatutoryReturns-Autumn2018_Fileset.mfs' -verbose
- import-fileset -verbose
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement