Check the NAS plugged in and then start the backup job

PowerShell script exchange

Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Thu Jul 11, 2013 5:44 am

Hey guys!

Is there any possiblity to check the Name of a NAS that is plugged in (NAS1 or NAS2)? I need it because the NAS will be switched every week and on Monday, I want to check if NAS1 or NAS2 is plugged in to start the certain backup job afterwards. Could you please help me? Thanks in advance,

Daniel
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Thu Jul 11, 2013 9:31 am 1 person likes this post

I’m wondering whether they are added under different drive letters. For instance, NAS#1 can be found under Z:\, meanwhile, NAS#2 under K:\.

If so, the following script is likely to meet your expectations:

Code: Select all
Asnp VeeamPSSnapin
$Job1 = Get-VBRJob -name "Name of your first Job"
$Job2 = Get-VBRJob -name "Name of your second Job"
$backupDrive = $null
$VolumeName1 = "Name of your first drive"   #For instance, Z:
$VolumeName2 = "Name of your second drive" #For instance, K:
get-wmiobject win32_logicaldisk | % {
    if ($_.DeviceID -eq $VolumeName1) {
        $backupDrive = $_.DeviceID
        Write-Output "$VolumeName1 drive found! The first job will be started"
        Start-VBRJob -job $Job1
    }
    if ($_.DeviceID -eq $VolumeName2) {
        $backupDrive = $_.DeviceID
        Write-Output "$VolumeName2 drive found!The second job will be started"
        Start-VBRJob -job $Job2 
    }
}


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Thu Jul 11, 2013 2:07 pm

Thank you for your quick reply! I am surprised that this is so simple code! Would it also be possible to ask for a certain ID or something like that, to be completely sure that it is either NAS1 or NAS2?
To execute this every week on Monday I simply have to create a planning task in Windows, right?

Thanks,
Daniel
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Thu Jul 11, 2013 2:53 pm

Assuming that they also have different volume names, it might be worth adding a part that will check volume names, as well. Another metrics I can come up with is the Provider Name that is usually represented by DNS name/IP address under which a certain device has been added to Windows system.

Anyway, you might want to run the following command first in order to understand what parameters of Windows volumes can be gotten and checked via PS:

Code: Select all
get-wmiobject win32_logicaldisk 


As the result you will get something similar:

Code: Select all
DeviceID     : Z:
DriveType    : 4
ProviderName : \\0.0.0.0\share
FreeSpace    : 11111111111
Size         : 11111111111
VolumeName   : Volume

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Fri Jul 12, 2013 7:24 am

Ok, thank you for this hint, but in my case the NAS doesn't consist of a drive letters, it will only be displayed in the network devices. The backup will either be performed under "\\NAS1\backup" or \\NAS2\backup", depending on which NAS is plugged in. Is there a way to solve it this way?
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Fri Jul 12, 2013 9:33 am

I still suggest running the command mentioned above to understand how NAS device is represented in your Windows OS and what particular parameters of it can be used later in order to differentiate two appliances.Unfortunately, it’s rather hard to me to speculate about it, since I don’t have any NAS device deployed in my environment and all my tests are based on usage of common CIFS shares.

To execute this every week on Monday I simply have to create a planning task in Windows, right?

Yep, Windows Scheduler should answer your requirements.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Fri Jul 12, 2013 1:43 pm

And is there a possibility to make two pings and depending on the successful ping the different jobs will be started? In this case, I wouldn't need to create a mapped network drive that is appearing to others.
Thanks in advance,

Daniel
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Fri Jul 12, 2013 1:54 pm 1 person likes this post

As far as I’m concerned, it’s Test-Connection that should be utilized in this case. In general, it’s a ping utility analogue:

Code: Select all
Asnp VeeamPSSnapin
$Job1 = Get-VBRJob -name "Name of your first Job"
$Job2 = Get-VBRJob -name "Name of your second Job"
$NAS1 = "Name/IP of your first NAS"   #Name/IP of your first NAS
$NAS2 = "Name/IP of your second NAS"   #Name/IP of your second NAS
If ((Test-Connection -ComputerName $NAS1 -quiet) -eq $True) {
        Write-Output "$NAS1  found! The first job will be started"
        Start-VBRJob -job $Job1
    }
If ((Test-Connection -ComputerName $NAS2 -quiet) -eq $True) {
        Write-Output "$NAS2 found!The second job will be started"
        Start-VBRJob -job $Job2 
    }


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Mon Jul 15, 2013 8:21 am

Thank you for your help, that's great!!
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Mon Jul 15, 2013 8:29 am

You’re welcome. Should any other questions arise, don’t hesitate to let me know. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Mon Jul 15, 2013 10:36 am

Just one question, now I have 3 Jobs for NAS1 and 3 Jobs for NAS2 and I simply want do disable the jobs from the unplugged NAS, can you tell me the line of code? Thanks!
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby neso » Mon Jul 15, 2013 10:53 am 1 person likes this post

Ok I got it, it is just
Code: Select all
$Job6 = Get-VBRJob -name "//name of the job"
$Job6.DisableScheduler()  #or    $Job6.EnableScheduler()


;)
neso
Novice
 
Posts: 7
Liked: 1 time
Joined: Thu Jul 11, 2013 5:25 am
Full Name: NESO Admin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby v.Eremin » Mon Jul 15, 2013 11:25 am

Glad that you’ve found the required method. You can also disable three jobs at once:

Code: Select all
$Jobs = Get-VBRJob | ? {($_.name -eq "Backup Job 1") -or ($_.name -eq "Backup Job 2") -or ($_.name -eq "Backup Job 3")}
$Jobs.disablescheduler()


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Check the NAS plugged in and then start the backup job

Veeam Logoby jmd » Tue Oct 01, 2013 4:40 pm

I know this is an old post, but this is just what I needed!
jmd
Lurker
 
Posts: 1
Liked: never
Joined: Thu Sep 26, 2013 1:48 pm
Full Name: J Delacruz


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests