Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- $appID = $args[0]
- foreach( $a in $args)
- {
- echo $a
- }
- #try
- #{
- $beta = $args[1]
- if( $beta -eq $null)
- {
- $beta = 0
- }
- #echo $beta
- #}
- #catch
- #{
- #$beta = 0
- #echo "Beta catch"
- #
- write-output '$appid = '$appID
- #$appID = "7"
- $dt = get-date -format G
- $connection = New-Object System.Data.SqlClient.SqlConnection
- $connection.ConnectionString = "Server=DB2\DB2;Database=VMI;Integrated Security=True;"
- $connection.Open()
- $command = $connection.CreateCommand()
- $command.CommandText = "SELECT LivePath FROM Dict_Application_Info WHERE ApplicationID = $AppID and ProgramType like 'Access%'"
- write-output '$command.CommandText = ' $command.CommandText
- $out = $command.ExecuteScalar()
- if (-not ($out -eq $null))
- {
- if ($out -like 'T:*')
- {
- $o = $out.split(':')
- $out = "\\vmi.local\data\testing" +$o[1]
- }
- elseif($out -like 'V:*')
- {
- $o = $out.split(':')
- $out = "\\vmi.local\data\vmi" +$o[1]
- }
- elseif ($out -like 'N:*')
- {
- $o = $out.split(':')
- $out = "\\vmi.local\data\Engineering" +$o[1]
- }
- $s = $out.split(".")
- echo $s
- if( $s.length -eq 3)
- {
- if ($beta -eq 0 )
- {
- $result = $s[0] +'.'+ $s[1]+"ToLocal."+$s[2]
- echo '$result =' + $result
- $check = $s[0] +'.'+ $s[1]+"ToLocal.l"+$s[2]
- echo '$check = ' + $check
- }
- else
- {
- $result = $s[0] +'.'+ $s[1]+"Beta."+$s[2]
- echo '$result =' + $result
- $check = $s[0] +'.'+ $s[1]+"Beta.l"+$s[2]
- echo '$check = ' + $check
- }
- $s2 = $result.split("\")
- $localCopy = "c:\apps\"+$s2[$s2.length-1]
- echo $localCopy
- }
- write-output '$out = ' $out
- if(-not (test-path $check))
- {
- echo (test-path $result)
- if(test-path $result)
- {
- $command.CommandText = "SELECT Version FROM Dict_ApplicationChangeLog_Info WHERE ApplicationID = $AppID and beta = $beta order by Version desc"
- $vers = $command.ExecuteScalar()
- echo '$vers = '$vers
- if ($vers -eq $null)
- {
- $vers = "1"
- }
- $command.CommandText = "SELECT Version FROM VersionTable WHERE ComputerName = '" + (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name + "' and ApplicationID = $appid And beta = $beta"
- $Myvers = $command.ExecuteScalar()
- #echo '$Myvers = '$Myvers
- #echo '$vers -eq $Myvers '$vers -eq $Myvers
- if($vers -eq $Myvers)
- {
- if (-not(test-path "c:\apps"))
- {
- mkdir "C:\apps"
- }
- #test-path $localCopy
- #test-path $result
- #(-not(test-path $localCopy)) -and (test-path $result)
- if (-not(test-path $localCopy))
- {
- copy-item -path $result -Destination $localCopy -ErrorAction Stop
- }
- $command.CommandText = "Update VersionTable SET Used = '$dt' WHERE ComputerName ='" + (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name + "' AND ApplicationID = $appID And beta = $beta"
- }
- else
- {
- if (-not(test-path "c:\apps"))
- {
- mkdir "C:\apps"
- }
- copy-item -path $result -Destination $localCopy -ErrorAction Stop
- #echo '$Myvers = '$Myvers
- if ($Myvers -eq $Null)
- {
- $command.CommandText = "Insert Into VersionTable VALUES( '" + (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name + "', $appID , $vers ,'$dt','$dt', $beta)"
- }
- else
- {
- $command.CommandText = "Update VersionTable SET Version = $vers,Updated = '$dt',Used = '$dt' WHERE ComputerName ='" + (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name + "' AND ApplicationID = $appID And beta = $beta"
- }
- }
- echo $command.CommandText
- $command.ExecuteNonQuery()
- ii $localCopy
- }
- else
- {
- write-output "Source File Doesnt Exist"
- if (test-path $localCopy)
- {
- ii $localCopy
- }
- else
- {
- if (test-path "c:\apps")
- {
- ii "C:\apps"
- }
- }
- }
- }
- else
- {
- write-output "File Open"
- if (test-path $localCopy)
- {
- ii $localCopy
- }
- else
- {
- if (test-path "c:\apps")
- {
- ii "C:\apps"
- }
- }
- }
- }
- else
- {
- write-output "Lookup failed"
- }
- }
- catch
- {
- echo "Catch"
- echo $_.Exception
- if (test-path "c:\apps")
- {
- ii "C:\apps"
- }
- }
- Finally
- {
- $connection.Close()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement