Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Install multiple applications in one powershell script

$
0
0

Hi,

I'm having issues with trying to run a powershell script for program that requires mutliple steps. I can run the each step separately in powershell just fine, but if I put them in one, they wind up overstepping themselves.  Is there a way to run these in sequence.

 

# This script installs the Oracle Client and CLASS Application.

 

 

# Part 1: Check to see if there is a Temp folder at the Root of C:.

 

Function Check_Folder

    {

 

    if(!(Test-Path c:\temp)) # Check to see if C:\Temp exists.

        {New-Item -type directory c:\temp} # If not, create the folder.

    }

 

 

# Part 2: Copy the Oracle Client and CLASS Application installation folders to C:\Temp.

 

 

Function Copy_Files

 

    {

    $Class_Path = "\\nsfs1\Software\EAdmin01\Vol1\APPS01\Apps and Drivers\Enterprise Apps\Class\"

 

    Copy-Item "$Class_Path\Oracle Client" -Destination C:\temp -Recurse - # Copies the Oracle Client folder to C:\Temp

 

    Copy-Item "$Class_Path\class7.2sp1" -Destination C:\temp -Recurse # Copies the Class Application folder to C:\Temp

 

    }

 

 

# Part 3: Install Oracle Client.

Function Install_Oracle

 

    {

 

    $class_exe = "c:\temp\oracle client\setup.exe"

 

    &$class_exe -silent -nowait -responseFile "c:\temp\oracle client\admin.rsp"

 

    }

 

 

# Part 4: Copy the SqlNet.ORA and TSNames.ORA files to C:\oracle\product\client_1\network\admin folder.

 

 Function Update_Oracle

 

    {  

 

    # Rename .ora files in Oracle Client before copying update files.

 

        $curDateTime = Get-Date -Format MMddyyyy

 

        $path = "C:\oracle\product\client_1\network\admin"

 

        Get-ChildItem $path *.ora  |

            Rename-Item -NewName {$_.Basename + '_' + $curDateTime +$_.Extension } # Renames .ora files with a time stamp as part of the new name.

 

    # Copy *.Ora files to Oracle Client   

 

        Copy-Item "c:\temp\oracle client\admin\*" C:\oracle\product\client_1\network\admin -recurse # Copies the *.ora files to admin folder for the oracle client.

 

    }

 

 

# Part 5: Give the local computer's group "Users" full rights to C:\Oracle.

 

Function Update_Oracle_Rights

 

    {

 

    $acl = Get-Acl c:\oracle

    $acl.SetAccessRuleProtection($True, $False)

    $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

    $acl.AddAccessRule($Rule)

    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

    $acl.AddAccessRule($Rule)

    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Authenticated Users","Modify, Synchronize","ContainerInherit, ObjectInherit", "None", "Allow")

    $acl.AddAccessRule($Rule)

    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

    $acl.AddAccessRule($Rule)

    Set-Acl c:\oracle $acl # Sets the new access rights

 

    }

 

# Part 6: Install CLASS for Windows.

 

Function Install_Class

 

    {

 

        $class1 = "c:\temp\Class7.2SP1"

        start-process $class1\installclass.bat

 

    }

 

# Part 7: Give the local computer's group "Users" full rights to C:\Program Files (x86)\Class for Windows or C:\Program Files\Class for Windows.

 

Function Update_Class_Rights

 

    {

 

    $os = Get-WmiObject win32_operatingsystem

 

    if ($os.OSArchitecture -eq '64-bit')

        {

        $acl = Get-Acl c:\program files\class for windows\7.21

        $acl.SetAccessRuleProtection($True, $False)

        $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Authenticated Users","Modify, Synchronize","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        Set-Acl c:\program files\class for windows\7.21 $acl # Sets the new access rights

        }

 

    Else

        {

        $acl = Get-Acl c:\program files\class for windows (x86)\7.21

        $acl.SetAccessRuleProtection($True, $False)

        $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Authenticated Users","Modify, Synchronize","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")

        $acl.AddAccessRule($Rule)

        Set-Acl c:\program files\class for windows (x86)\7.21 $acl # Sets the new access rights

        }

 

    }

 

 

# Part 8: Copy C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Class for Windows\7.21\Central Login.lnk to C:\Users\Public\Desktop folder.

 

Function Class_Shortcut

 

    {

 

    Copy-Item 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Class for Windows\7.21\Central Login.lnk' -Destination C:\Users\Public\Desktop 

        # Copies the Central Login shortcut to the Public Desktop folder.

 

    }

 

 

# Part 9: Delete the Oracle Client and CLASS Application installation folders in C:\Temp

 

Function Delete_Files

 

    {    

 

    Remove-Item 'c:\temp\Oracle Client' -Recurse # Deletes the Oracle Client folder and all subfolders and files contained within.

 

    Remove-Item 'c:\temp\class7.2sp1' -Recurse # Deletes the Class Application folder and all subfolders and files contained within.

 

    }

 

 

# Part 10: Notify software installer that the application has been completed.

 

Function Notify

 

    {

 

    Add-Type -AssemblyName System.Speech

 

        $synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer

 

        $synthesizer.Speak('Class for Windows 7.21 has been successfully installed.')

 

    Add-Type -AssemblyName System.Windows.Forms

 

        [System.Windows.Forms.MessageBox]::Show("Class for Windows 7.21 has been successfully installed.")

 

    }

 

#Start-Process -FilePath Powershell -ArgumentList "-NoExit -NoProfile -Command & {. .\CLASS_Installation2.ps1 Check_Folder}" -Wait

#Start-Process -FilePath Powershell -ArgumentList "-NoExit -NoProfile -Command & {. .\CLASS_Installation2.ps1 Copy_Files}"

 

workflow Install_Class

    {

        Check_Folder

        Copy_Files

        Install_Oracle

        Update_Oracle

        Update_Oracle_Rights

        Install_Class

        Update_Class_Rights

        Class_Shortcut

        Class_Shortcut

        Delete_Files

        Notify

    }

 

    Install_Class


Viewing all articles
Browse latest Browse all 6937

Trending Articles