PowerShell script exchange
Post Reply
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

Check the NAS plugged in and then start the backup job

Post by neso »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » 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.
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso »

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?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » 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.
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso »

Thank you for your help, that's great!!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

You’re welcome. Should any other questions arise, don’t hesitate to let me know. Thanks.
neso
Novice
Posts: 7
Liked: 1 time
Joined: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso »

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: Jul 11, 2013 5:25 am
Full Name: NESO Admin
Contact:

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

Post by neso » 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()
;)
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
jmd
Lurker
Posts: 1
Liked: never
Joined: Sep 26, 2013 1:48 pm
Full Name: J Delacruz
Contact:

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

Post by jmd »

I know this is an old post, but this is just what I needed!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 14 guests