Jump to content

ziggemonster

Members
  • Gesamte Inhalte

    1
  • Registriert seit

  • Letzter Besuch

Beiträge erstellt von ziggemonster

  1. Hallo zusammen,

     

    das Script soll per Powershell T-SQL-Scripts ausführen. Wird der Codeschnipsel um den es geht einzeln ausgeführt funktioniert er. Wird das ganze Script ausgeführt funktioniert er nicht. Lasse ich das Script dann ein zweites mal laufen funktioniert es... Ich bin bissl ratlos und hoffe ihr könnt mir helfen. Das Script ändert bzw. fügt noch ein paar Sachen hinzu nach einer SQL Server Installation.

     

    Ich bin noch Anfänger und weiß das sicherlich das ein oder andere im Code unten besser gemacht werden könnte :-)

     

    Vielen Dank schon mal im voraus, ist ja auch viel zu lesen...

     

    Hier der Codeschnipsel um den es geht:

    ###Execute SQL-Querys
    Try
    {
    Write-Host -ForegroundColor Yellow "Execute 
    $BdcConInst and
    $MainSolPath and
    $BdcMainSolPath..."
     
     
    ##Cluster: e.g.: BY-FOCGRP01\I001
    If($focgInfo){
    $ServerInst = "$focgInfo\$instance"
    }
    ##Default instance e.g.: BY0KDG
    elseif ($DefInstance){
    $ServerInst = $env:COMPUTERNAME
    }
    ##Standalone named instance e.g.: BY0KDG\I001
    else{
    $ServerInst = "$env:COMPUTERNAME\$instance"
    }
     
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$BdcConInst" 
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$MainSolPath" 
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$BdcMainSolPath" 
     
    Write-Host -ForegroundColor Cyan "$ServerInst"
    }
    Catch
    {
    Write-Host -ForegroundColor Magenta "Not able to execute T-Sql scripts, please execute 
    $BdcConInst and
    $MainSolPath and
    $BdcMainSolPath manually"
     
    } 
    

    und hier das gesamte Script:

     
     
    #region - getvariables
    Param(
    [string]$localinstallpath, 
    [string]$instance
    )
    # $localinstallpath = "D:\sqlinstall"
    # $instance= "I00AA"
     
    $BdcConInst = "\\XXXXX\scripte$\TSQL\Config\bdc_configure_instance.sql"
    $MainSolPath = "\\XXXX\scripte$\TSQL\database_maintenance\MaintenanceSolution_V150619.sql"
    $BdcMainSolPath = "\\XXXXX\scripte$\TSQL\database_maintenance\BDCMaintenanceSolution.sql"
     
    $DefInstance = $configfile.SQLSERVER.Server.DefaultInstance
    #######################################################################################################
    import-module failoverclusters -ErrorAction SilentlyContinue
    function add_user_to_local_group {
     
    param([Parameter(Mandatory=$true)][string] $username,
    [Parameter(Mandatory=$true)][string] $group,
    [Parameter(Mandatory=$false)][switch] $clear)
    $domain=$env:computername
    $computer=$env:computername
    if ($clear.IsPresent) { Clear-Host } else { Write-Host "" }
    #----------------------------
    # try to retrieve sid via WMI
    #----------------------------
    $res=(Get-WmiObject win32_useraccount -Filter "Domain = '$computer' and Name = '$username'")
    #--------------------------------------------------------
    # check if user was found and if the result is unambiguos
    #--------------------------------------------------------
    if ($res.length -gt 1) { Write-host -ForegroundColor Yellow "Result is ambibuous" }
    elseif ($res.Length -eq "")
    {
    #----------------------------------------------------------------------------
    # WMI-call did not return ANY result. User is maybe a managed service account
    # Trying CMD command "SC" to retrieve SID
    #----------------------------------------------------------------------------
     
    $result = (& 'C:\Windows\System32\sc.exe' 'showsid' $username)
     
    $status=($result | Select-String -Pattern Status)
    $status=([string]$status).replace('STATUS: ','')
    #------------------------------------------------------------------------------------
    # Because the SC command returns a SID for ANY user (even those who are not existing)
    # we have to perform an additional check
    #------------------------------------------------------------------------------------
    if ($status -eq "Active")
    {
    $SID=($result | Select-String -Pattern SID)
    $SID=([string]$SID).replace('SERVICE SID: ','')
     
    #-------------- finally add user to group via SID
    Write-Host -ForegroundColor Yellow "Adding SID $SID of managed"
    Write-Host -ForegroundColor Yellow "user account ""$username"" to group ""$Group"" on ""$computer"""
    ([ADSI]"WinNT://$computer/$Group,group").psbase.Invoke("Add",([ADSI]"WinNT://$SID").path) 
    }
    else { Write-Host -ForegroundColor Yellow "User ""$username"" was not found or inactive" }
    }
    else
    {
    #---------------------------------------------------------------------
    # WMI call returned ONE object. This account is now added to the group
    #---------------------------------------------------------------------
    $sid=[string]$res.sid
    Write-Host -ForegroundColor Yellow "Adding SID $SID of normal"
    Write-Host -ForegroundColor Yellow "user account ""$username"" to group ""$Group"" on ""$computer"""
    ([ADSI]"WinNT://$computer/$group,group").psbase.Invoke("Add",([ADSI]"WinNT://$sid").path)
    }
    }
     
     
     
    #######################################################################################################
     
    #sample:
    #[string]$instance = "DEV01"
    #[string]$localinstallpath = "C:\sql2012"
    [string]$localcomputer = get-content env:computername 
    if (!$localinstallpath -or !$instance )
    {
    Write-Host -foregroundcolor red "Parameter missing ! (sample: .\post_installation_tasks.ps1 C:\sql2012 DEV01)"
    exit
    }
     
    Try
    { 
    #load ini file 
    [string]$dir = dir $localinstallpath | Where-Object { $_.name -like "*.ini"} | sort name
    #write-host $dir.Count
    IF ($dir.Count -lt 2)
    {
    IF ($dir)
    {
    #write-host -foregroundcolor yellow $dir "was selected".
    $fullpath = $localinstallpath + "\" + $dir
    }
    ELSE 
    {
    write-host -foregroundcolor red "No configuration file found in" $localinstallpath
    }
    }
    ELSE 
    {
    write-host -foregroundcolor red "More that 1 configuration file was found in" $localinstallpath "Please ensure that only one configuration file resides in setup location !"
    write-host -foregroundcolor red "Found the following files:" $dir
    exit
    }
    }
     
    Catch
    {
    write-host -foregroundcolor red "Unexpected error during finding INI template file."
    exit
    }
    # determine the install action 
    Try 
    {
    $actionFOCluster = Select-String -path $fullpath -SIMPLEMATCH "ACTION=""InstallFailoverCluster"""
    $actionAddNode = Select-String -path $fullpath -SIMPLEMATCH "ACTION=""AddNode"""
    $actionStandAlone = Select-String -path $fullpath -SIMPLEMATCH "ACTION=""Install"""
    $sqlfeatures = Select-String -path $fullpath -SIMPLEMATCH "FEATURES="
    }
    Catch
    {
    write-host -foregroundcolor red "Unexpected error determining install action in INI template file."
    exit
    }
     
    Try
    {
    if($sqlfeatures -like "*SQLENGINE*")
    { 
    #get SQL Server Details
     
    [array]$sql = Get-WmiObject win32_service -computer . | Where-Object {$_.name -like "*$instance" } | Where-Object {$_.PathName -like "*sqlservr.exe*" } | select Name, StartName, PathName
    $sqluser = $sql | select -ExpandProperty startname
    $path = $sql | select -ExpandProperty pathname
    $instname = $sql | select -ExpandProperty name
     
    # get TCP Port for SQL Server instance
    $RegKey = "hklm:\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL"
    $reg = Get-ItemProperty -path $RegKey -name $instance
    $regId = [String]$reg.$instance
    $RegKey = "hklm:\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\$regId\\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
    $dyntcpreg = Get-ItemProperty -path $RegKey -name "TcpDynamicPorts"
    $tcpreg = Get-ItemProperty -path $RegKey -name "TcpPort"
    $TcpDynPort = [String]$dyntcpreg.TcpDynamicPorts
    $TcpPort = [String]$tcpreg.TcpPort
     
    $pathsplit = $path.ToString().split("-") # split on "-"
    $exepath = $pathsplit[0]
    }
     
    }
    Catch 
    {
    Write-Host -foregroundcolor red "Could obtain SQL Server detail information for Instance:" $instance
    exit
    }
    Try
    {
    if($sqlfeatures -like "*SSAS*")
    { 
    #get SSAS Server Details
    [array]$ssassql = Get-WmiObject win32_service -computer . | Where-Object {$_.name -like "*$instance" } | Where-Object {$_.PathName -like "*msmdsrv.exe*" } | select Name, StartName, PathName
    $ssassqluser = $ssassql | select -ExpandProperty startname
    $ssaspath = $ssassql | select -ExpandProperty pathname
    $ssasinstname = $ssassql | select -ExpandProperty name
     
    $ssaspathsplit = $ssaspath.ToString().split("-") # split on "-"
    $ssasexepath = $ssaspathsplit[0]
     
    }
    }
    Catch 
    {
    Write-Host -foregroundcolor red "Could obtain SSAS detail information for Instance:" $instance
    exit
    }
    Try
    {
    if($sqlfeatures -like "*SSRS*")
    { 
    #get SSRS Server Details
    [array]$ssrssql = Get-WmiObject win32_service -computer . | Where-Object {$_.name -like "*$instance" } | Where-Object {$_.PathName -like "*ReportingServicesService.exe*" } | select Name, StartName, PathName
    $ssrssqluser = $ssrssql | select -ExpandProperty startname
    $ssrspath = $ssrssql | select -ExpandProperty pathname
    $ssrsinstname = $ssrssql | select -ExpandProperty name
     
    $ssrsexepath = $ssrspath 
    }
    }
    Catch 
    {
    Write-Host -foregroundcolor red "Could obtain SSRS detail information for Instance:" $instance
    exit
    }
     
    #endregion - getvariables
    #region - setfixedTCPPort
    # set the TCPport to the calculated TCP Dynamic Port 
     
    try
    { 
    if($sqlfeatures -like "*SQLENGINE*")
    { 
     
    # check for TCP Port 
    If ($TcpPort)
    {
    write-host "TCP Port for SQL Server instance is (already) set to:" $TcpPort
    }
     
    # set TCP Port for SQL Server instance if not set yet to port Number of dynamic port 
    If (!$TcpPort)
    {
    write-host "Setting TCP Port for SQL Server instance to:" $TcpDynPort 
    Set-ItemProperty -path $RegKey -name "TcpPort" -value $TcpDynPort 
    Set-ItemProperty -path $RegKey -name "TcpDynamicPorts" -value ""
    $TcpPort = $TcpDynPort 
    }
    }
    }
    catch
    {
    Write-Host -foregroundcolor red "Could not set the TCP port for SQL Server instance:" $instance
    exit
    }
    #endregion - setfixedTCPPort
     
     
    #region - firewallrule
    $ssb = "C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe"
     
    if(Get-NetFirewallApplicationFilter -Program "*sqlbrowser.exe") {echo "SQL Server Browser already installed"}
    else {
    netsh advfirewall firewall add rule name="SQL Server Browser (Shared)" dir=in action=allow program= $ssb enable=yes
    Write-Host -ForegroundColor Yellow "Added SQLServer Browser"
    }
    try 
    {
     
    if($sqlfeatures -like "*SQLENGINE*")
    { 
    if(Get-NetFirewallRule -DisplayName "SQL Server Autoinstall Rule ($instance)" -ErrorAction SilentlyContinue ) 
    {
    echo "SQL Server engine rule already installed"
    }
    Else
    {
    If($exepath)
    {
    Write-Host "Applying Firewall Rules for SQL Server instances:" $instance
    Write-Host "Found the SQL Server directory:" $exepath
    $exepath = $exepath.Trim()
    netsh advfirewall firewall add rule name="SQL Server Autoinstall Rule ($instance)" dir=in action=allow program= $exepath enable=yes
    }
    }
    }
    }
    catch 
    {
    Write-Host -foregroundcolor red "Could not set Windows Firewall Rules for SQL Server instances"
    }
    ### add SSAS rule 
    try 
    {
     
    if($sqlfeatures -like "*SSAS*")
    { 
    if(Get-NetFirewallRule -DisplayName "SQL Server Autoinstall Rule SSAS ($instance)" -ErrorAction SilentlyContinue )
    {
    echo "SQL Server SSAS rule already installed"
    }
    Else
    {
    If($ssasexepath)
    {
    Write-Host "Applying Firewall Rules for SQL Server Analysis Services (SSAS) instances:" $instance
    Write-Host "Found the SQL Server directory:" $ssasexepath
    $ssasexepath = $ssasexepath.Trim()
    netsh advfirewall firewall add rule name="SQL Server Autoinstall Rule SSAS ($instance)" dir=in action=allow program= $ssasexepath enable=yes
    }
    }
    }
    }
    catch 
    {
    Write-Host -foregroundcolor red "Could not set Windows Firewall Rules for SQL Server Analysis Services (SSAS)"
    }
    #endregion - firewallrule
     
    $serverName="localhost" 
    #---------------------------------------
    # Check if server is member of a cluster
    #---------------------------------------
    $ErrorActionPreference = "SilentlyContinue"
    if ((Get-WMIObject -Class MSCluster_ResourceGroup -ComputerName $serverName -Namespace root\mscluster) -ne $null) {
    #-------------------------
    # Server is cluster member
    #-------------------------
    $ErrorActionPreference = "Continue"
     
    if (! (Get-WindowsFeature -ComputerName $serverName RSAT-Clustering-AutomationServer).Installed) {
    Write-Host -ForegroundColor Yellow "Cluster Automation Tools missing - will be installed"
    Install-WindowsFeature -ComputerName $serverName RSAT-Clustering-AutomationServer
    Write-Host ""
    }
    if (! (Get-WindowsFeature -ComputerName $serverName RSAT-Clustering-CmdInterface).Installed) {
    Write-Host -ForegroundColor Yellow "Cluster Commandline Tools missing - will be installed"
    Install-WindowsFeature -ComputerName $serverName RSAT-Clustering-CmdInterface
    Write-Host ""
    }
    } else {
    #--------------------------------------------------
    # Server is NOT cluster member - nothing more to do
    #--------------------------------------------------
    $ErrorActionPreference = "Continue"
    } 
    #region - TempDB
    #Write-Host "Split TempDB on SQL Server" 
    #Write-Host "to be done"
    # exec existing script TempDB 
    #endregion - TempDB
    #region - Number of ERRORLOG Files
    # BEGIN - 2015.09.08 - Added step "Increase number of ERRORLOG files" -
    if($sqlfeatures -like "*SQLENGINE*" -and 1 -eq 0) {
    # get TCP Port for SQL Server instance
    try {
    $RegKey = "hklm:\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL"
    $reg = Get-ItemProperty -path $RegKey -name $instance
    $regId = [String]$reg.$instance
    $regKey = "hklm:\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\$regId\\ClusterState"
    $isClustered = Get-ItemProperty -path $RegKey -name "SQL_Engine_Core_Inst" | select -ExpandProperty SQL_Engine_Core_Inst
     
    if ($isClustered) {
    $regKey = "hklm:\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\$regId\\Cluster"
    [String]$Servername = Get-ItemProperty -path $RegKey -name "Clustername" | select -ExpandProperty Clustername
    [String]$SQLServername = "$Servername\$instance"
    } else {
    [String]$SQLServername = ".\$instance"
    }
     
    $conn = New-Object System.Data.SqlClient.SqlConnection
    $conn.ConnectionString = "Data Source=$SQLServername;Integrated Security=SSPI;"
    $conn.Open()
    $cmd = New-Object System.Data.SqlClient.SqlCommand
    $cmd.connection = $conn
    #$cmd.CommandText = "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'NumErrorLogs',REG_DWORD,99"
    $cmd.CommandText = "
    USE [master];
    EXECUTE xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', REG_DWORD, 99;
    BEGIN TRANSACTION
    DECLARE @ReturnCode INT;
    SELECT @ReturnCode = 0;
    IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Maintenance' AND category_class=1)
    BEGIN
    EXECUTE @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Maintenance';
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    END
    IF EXISTS (SELECT name FROM msdb.dbo.sysjobs WHERE name=N'Cycle_Log')
    BEGIN
    PRINT 'Job already exists ...' 
    GOTO EndSave;
    END
    DECLARE @jobId BINARY(16);
    EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Cycle_Log', 
    @enabled=1, 
    @notify_level_eventlog=0, 
    @notify_level_email=0, 
    @notify_level_netsend=0, 
    @notify_level_page=0, 
    @delete_level=0, 
    @description=N'Cycle SQL Server ErrorLog daily.', 
    @category_name=N'Database Maintenance', 
    @owner_login_name=N'sa', @job_id = @jobId OUTPUT;
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Step_Cycle_Log', 
    @step_id=1, 
    @cmdexec_success_code=0, 
    @on_success_action=1, 
    @on_success_step_id=0, 
    @on_fail_action=2, 
    @on_fail_step_id=0, 
    @retry_attempts=0, 
    @retry_interval=0, 
    @os_run_priority=0, @subsystem=N'TSQL', 
    @command=N'EXECUTE master.sys.sp_cycle_errorlog;', 
    @database_name=N'master', 
    @flags=0;
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1;
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Sched_Cycle_Log', 
    @enabled=1, 
    @freq_type=4, 
    @freq_interval=1, 
    @freq_subday_type=1, 
    @freq_subday_interval=0, 
    @freq_relative_interval=0, 
    @freq_recurrence_factor=0, 
    @active_start_date=20070907, 
    @active_end_date=99991231, 
    @active_start_time=60000, 
    @active_end_time=235959;
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)';
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) 
    GOTO QuitWithRollback;
    COMMIT TRANSACTION
    GOTO EndSave
    QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
    EndSave:
    PRINT ('...Done!')
    PRINT ('')"
    $cmd.executenonquery()
    $conn.Close()
    }
    catch 
    {
    Write-Host -foregroundcolor red "Could not increase the number of ERRORLOG files"
    Write-Host -ForegroundColor red $_.Exception.Message
    }
    }
    # END - 2015.09.08 - Added step "Increase number of ERRORLOG files" 
    #endregion - Number of ERRORLOG Files
    #Stop service and display service status
    Try
    {
    if($iniFile -eq 2)
    {
    Stop-Service -DisplayName "SQL Server Analysis Services ($instance)" -ErrorAction SilentlyContinue
    }
    else
    {
    Stop-ClusterResource -Name "Analysis Services ($instance)" -ErrorAction SilentlyContinue
    }
    Stop-Service -DisplayName "SQL Server Reporting Services ($instance)" -ErrorAction SilentlyContinue
    Get-Service -DisplayName "SQL Server Analysis Services ($instance)" -ErrorAction SilentlyContinue
    Get-Service -DisplayName "SQL Server Reporting Services ($instance)" -ErrorAction SilentlyContinue
    Get-Service -DisplayName "SQL Server Integration Services 12.0" -ErrorAction SilentlyContinue
    Get-Service -DisplayName "SQL Server Agent ($instance)" -ErrorAction SilentlyContinue
    Get-Service -DisplayName "SQL Server ($instance)"-ErrorAction SilentlyContinue
    }
    Catch
    {
    Write-Host -ForegroundColor Red "Stopping services failed!"
    }
    Try
    {
    add_user_to_local_group -group 'logon_as_a_service' -username ("MSSQLFDLauncher$" + $instance)
    }
    Catch
    {Write-Host -ForegroundColor Cyan "SID User already added...."}
    Write-Host " `n"
    #Set Force Encryption in registry
    Try
    {
    $RegKey = "HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL1[123].$instance\MSSQLServer\SuperSocketNetLib";
    Set-ItemProperty -path $RegKey -name ForceEncryption -value "1";
    Write-Host -ForegroundColor Yellow "Setting Force Encryption..... OK"
    }
    catch
    {
    Write-Host -ForegroundColor Red "Error during setting -ForceEncryption- in registry"
    }
    Write-Host " `n"
    ##### TraceFlags
    Try
    {
    Write-Host -ForegroundColor Cyan "Setting Startup Parameter......"
    .\Add-SqlServerStartupParameter.ps1 '-T1117' $instance
    .\Add-SqlServerStartupParameter.ps1 '-T1118' $instance
    .\Add-SqlServerStartupParameter.ps1 '-E' $instance
    }
    Catch
    {Write-Host -ForegroundColor Red "Failed to set startup parameters"}
    Write-Host " `n"
    ###Execute SQL-Querys
    Try
    {
    Write-Host -ForegroundColor Yellow "Execute 
    $BdcConInst and
    $MainSolPath and
    $BdcMainSolPath..."
     
     
    ##Cluster: e.g.: BY-FOCGRP01\I001
    If($focgInfo){
    $ServerInst = "$focgInfo\$instance"
    }
    ##Default instance e.g.: xxxxxx
    elseif ($DefInstance){
    $ServerInst = $env:COMPUTERNAME
    }
    ##Standalone named instance e.g.: xxxxx\I001
    else{
    $ServerInst = "$env:COMPUTERNAME\$instance"
    }
     
    #.\tsql.ps1 $ServerInst
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$BdcConInst" -OutputSqlErrors -DisableVariables
    Write-Host $BdcConInst -ForegroundColor Green "OK" 
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$MainSolPath" -OutputSqlErrors -DisableVariables
    Write-Host $MainSolPath -ForegroundColor Green "OK"
    Invoke-Sqlcmd -ServerInstance "$ServerInst" -Database "master" -InputFile "$BdcMainSolPath" -OutputSqlErrors -DisableVariables
    Write-Host $BdcMainSolPath -ForegroundColor Green "OK"
    Write-Host -ForegroundColor Cyan "$ServerInst"
    }
    Catch
    {
    Write-Host -ForegroundColor Magenta "Not able to execute T-Sql scripts, please execute 
    $BdcConInst and
    $MainSolPath and
    $BdcMainSolPath manually"
    Write-Host -ForegroundColor Green $ServerInst
    }
    ###### Setting cluster ressources dependencys
    Try
    {
    If ($iniFile -eq 1){
    Write-Host -ForegroundColor Cyan "Setting dependencys for cluster ressources..."
    $clusterRes = Get-ClusterGroup -name $focgInfo | Get-ClusterResource 
     
    $CServer = $clusterRes.Name -eq "SQL Server ($iname)"
    $CAgent = $clusterRes.Name -eq "SQL Server Agent ($iname)"
    $Croot = $clusterRes.Name -eq "$iname"
    $CData = $clusterRes.Name -like "*Data*"
    $CLog = $clusterRes.Name -like "*Log*"
    $CTemp = $clusterRes.Name -like "*Temp*"
     
    Set-ClusterResourceDependency "$CServer" "([SQL Network Name ($focgInfo)]) and ([$iname]) and ([$CData])"
    Get-ClusterResourceDependency $CServer
    If($CLog){
    Add-ClusterResourceDependency "$CServer" "[$CLog]" -ErrorAction SilentlyContinue
    Set-ClusterResourceDependency "$CLog" "[$iname]" -ErrorAction SilentlyContinue
    Get-ClusterResourceDependency $CLog
    }
    If($CTemp){
    Add-ClusterResourceDependency "$CServer" "[$CTemp]" -ErrorAction SilentlyContinue
    Set-ClusterResourceDependency "$CTemp" "[$iname]" -ErrorAction SilentlyContinue
    Get-ClusterResourceDependency $CTemp
    }
     
    Set-ClusterResourceDependency "$CAgent" "[$CServer]"
    Get-ClusterResourceDependency $CAgent
    Set-ClusterResourceDependency "$Croot" "[SQL Network Name ($focgInfo)]"
    Get-ClusterResourceDependency $Croot
    Set-ClusterResourceDependency "$CData" "[$iname]"
    Get-ClusterResourceDependency $CData
    }
    }
    Catch
    {
    Write-Host -ForegroundColor Red "Not able to set the dependencys on cluster ressources!!"
    }
     
    ###### Remove Analysis service from cluster group
    Try
    {
    If($focgInfo){
    Remove-ClusterResource "Analysis Services ($iname)" -force
    }
    }
    Catch{
    Write-Host -ForegroundColor Red "Removing Analysis service from cluster group failed!"
    }
     
     
    Write-Host "Script done!"
    <#
    Try
    {
    ## Chuck part
    Add-Type -AssemblyName System.Windows.Forms
    $Label = New-Object System.Windows.Forms.Label
    $Form = New-Object system.Windows.Forms.Form
    $Form.Text="Chuck Norris approved!"
    $Form.AutoSize = $True
    $Form.MinimizeBox = $False
    $Form.MaximizeBox = $False
    $Form.WindowState = "Normal"
    $Form.StartPosition = "CenterScreen" 
    $img = [System.Drawing.Image]::Fromfile('\\xxxxxx\Shares\xxxxxx\chuck1.png')
    $pictureBox = new-object Windows.Forms.PictureBox
    $pictureBox.Width = $img.Size.Width
    $pictureBox.Height = $img.Size.Height
    $pictureBox.Image = $img
    $form.controls.add($pictureBox)
    [void]$Form.ShowDialog()
    }
    Catch{
    Write-Host -ForegroundColor Red "Can`t do the Chuck part, dosen`t matter! :-)"
    }#> 
    

    Vielen Dank

     

×
×
  • Neu erstellen...