Popular Posts

Monday, July 31, 2023

Checking EMC Networker configuration on new Windows Server builds

Background

You have been tasked to find out if EMC Networker is configured properly on your new Windows Server builds. This could be achieved by running an Ansible Playbook coupled with a PowerShell script.


Script

Playbook

#Define list of servers and their respective login details, this could be achieved differently depending on your infrastructure design
- name: capture servers list
hosts: localhost
vars:
- servers: "{{ myhost.split(',') }}"
gather_facts: false
tasks:
- import_tasks: automation-add-group.yml

- name: Check build status for windows
hosts: temp_group
gather_facts: false
tasks:
- name: Check for networker agent
win_shell: if(Get-WmiObject -Class Win32_Product | where Name -eq 'Networker') { write-host "Found" } else { write-host "Not Found" }
register: backupagent
failed_when: "'Not Found' in backupagent.stdout"
ignore_errors: true

- name: make sure networker service is running
win_service:
name: nsrexecd
state: started
register: srtbckup
ignore_errors: true

#If networker service is not running
- block:
- name: rename nsr folder
win_file:
path: C:\Program Files\EMC NetWorker\nsr\res\nsrladb
state: absent
- name: make sure network service is running
win_service:
name: nsrexecd
state: started
when: srtbckup is failed
ignore_errors: true

- pause:
seconds: 30

    #Calls the PowerShell script
- name: Check backup configuration
script: backservercheck.ps1
register: backupserver
failed_when: "'Backup client configured properly' not in backupserver.stdout"
ignore_errors: true


PowerShell

In this example, we wanted to check the backup configuration on 2 sites where each site had their own Backup servers. Hence, this script taps on the naming convention of each Windows Server to determine which Backup server it should connect to.

$hostname = $env:COMPUTERNAME

if ($hostname -like '*naming convention 1*') {

$backserverlist = @('backup server 1 - site 1','backup server 2 - site 1')

foreach ($bckupserver in $backserverlist) {

 #Define nsr command
        $command = "echo print type: nsr client; name: $hostname | nsradmin -s $bckupserver -p nsrd"

 #Run nsr command in cmd
        $output = cmd.exe /c $command

if($output -like '*scheduled backup: Enabled*') {

Write-Host "Backup client configured properly"
break

}

}

} elseif ($hostname -like '*naming convention 2*') {

$backserverlist = @('backup server 1 - site 2','backup server 2 - site 2')

foreach ($bckupserver in $backserverlist) {

$command = "echo print type: nsr client; name: $hostname | nsradmin -s $bckupserver -p nsrd"

$output = cmd.exe /c $command

if($output -like '*scheduled backup: Enabled*') {

Write-Host "Backup client configured properly"
break

}

}

}

No comments:

Post a Comment