SureReplica Custom Script to run chkdsk

PowerShell script exchange

SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Tue Apr 08, 2014 5:01 pm

Hi, is it possible for a SureReplica custom script to run chkdsk on the VM(s) in the job and only succeed if the chkdsk operation ends with:

"Windows has scanned the file system and found no problems."

Main reason is because just booting them up and ping testing them isn't enough, I've had corruption in my replica VMs recently and some booted fine but reported errors on the other drives due to corruption.

I know there is some built in tests but these are no good for just file servers etc.

Thanks
Simon
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby nefes » Tue Apr 08, 2014 5:08 pm

You can create simple .ps1 (or any other script language you like) script, that will call chkdsk remotely, parse it's output and return 0 if chkdsk returned that string.
Generally SureReplica and SureBackup can run any command, that can be run in Windows Shell on Backup console and report success only if exit code is 0.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Tue Apr 08, 2014 5:13 pm

Ok great, any chance you give me a starting point, I have no idea how to "call chkdsk remotely and parse it's output" ?!
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby nefes » Wed Apr 09, 2014 9:16 am

Here is the sample script to achieve your goal.
Please be aware that you need to set up authentication mode that will fit you security settings.
Code: Select all
$result = Invoke-Command -ComputerName <name> -ScriptBlock {chkdsk c:} -Authentication CredSSP -Credential $creds #add keys of chkdsk you need
if ($result -contains "Windows has scanned the file system and found no problems.")
{
    return 0 #scan returned that all was good, report success to SureReplica
}
else
{
    return 1 #string not found, chkdsk found some errors. you can add here any other actions, for example logging $result or sending e-mail with it in body
}
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Wed Apr 09, 2014 11:26 am

Thanks! :)

So do I call that script with %vm_fqdn% for the virtual lab VM and credentials?

Sorry I really don't have much knowledge or experience with this or powershell. Can I have the credentials hard coded with a domain account, eg. -Credential DOMAIN\USERNAME password ?

I guess I also need it to see what drives that are in that VM and scan all of them somehow.
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby nefes » Wed Apr 09, 2014 12:13 pm

CaptainFred wrote:So do I call that script with %vm_fqdn% for the virtual lab VM and credentials?

I believe, it should be masquerade ip to ensure you are connecting to surereplica vm, not production one.

CaptainFred wrote:Sorry I really don't have much knowledge or experience with this or powershell. Can I have the credentials hard coded with a domain account, eg. -Credential DOMAIN\USERNAME password ?

You can review types of authentication, allowed in Invoke-Command, at Technet: http://technet.microsoft.com/en-us/libr ... 49719.aspx
Some of them requires you to store and pass username and password, others use the account that is started the script. Also most of them require some settings in your domain and/or vm. It is too much different types to describe all of them in forum post.

CaptainFred wrote:I guess I also need it to see what drives that are in that VM and scan all of them somehow.

I'm not so good with chkdisk command, maybe there's some keys that allow you to check all connected disks.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby v.Eremin » Wed Apr 09, 2014 1:21 pm

You can, probably, get list of all connected drives, and, then, perform chkdsk on them. The corresponding commands used below has been appropriated from this article:

Code: Select all
Foreach ($LogicalDisk in (Get-WmiObject Win32_logicaldisk))
{
$LogicalDisk.Chkdsk
}


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

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Wed Apr 09, 2014 5:40 pm

nefes wrote:
CaptainFred wrote:So do I call that script with %vm_fqdn% for the virtual lab VM and credentials?

I believe, it should be masquerade ip to ensure you are connecting to surereplica vm, not production one.


Ok, so do I need to use %vm_ip% then instead?

This all seems very complicated. I'm not even sure what to put in the "Name" and "Path" boxes in the Test Scripts option? Do I just point it directly to a ps1 file?

Thanks
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby v.Eremin » Thu Apr 10, 2014 8:33 am

Do I just point it directly to a ps1 file?

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

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Thu Apr 10, 2014 5:50 pm

ok, do I need to use %vm_ip% then instead?
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby v.Eremin » Thu Apr 10, 2014 7:49 pm

It seems that you can disregard "argument" section, as the script itself has the part responsible for connecting to the given VM. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby tdewin » Fri Apr 11, 2014 4:11 pm

For storing the password you can use convertfrom-securestring to save the password your requested with get-credential in an encrypted way. Watch out, it can only be decrypted by the user that stored the password in the first place. So your code must run using this user, which I guess will be the backup service user (but haven't got the time to test that)

Code: Select all
$passfile = "c:\d\encrypted.pass"
$creds = get-credential
$creds.password | ConvertFrom-SecureString | out-file $passfile


Then you can retrieve the password like this and create "credentials"
Code: Select all
$passfile = "c:\d\encrypted.pass"
$credlogon = New-Object PSCredential "domain\user",(get-content $passfile | ConvertTo-SecureString)


http://technet.microsoft.com/en-us/maga ... 14574.aspx
http://technet.microsoft.com/en-us/libr ... 49814.aspx
http://technet.microsoft.com/en-us/libr ... 49818.aspx
tdewin
Veeam Software
 
Posts: 1043
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Fri Apr 11, 2014 4:31 pm

Thanks but I don't really care if the password is in plain text in the script because the only people who could see it are people with access to the server which are admins anyway. Or is that not possible because of security in Windows etc?
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby tdewin » Tue Apr 15, 2014 12:16 am

I didn't test it but it seems, you can use convertto-securestring with the -asplaintext -force parameter. This you can then reuse to create credentials

Code: Select all
$securestring = ConvertTo-SecureString -string "mynotsosecretpass" -asplaintext -force
New-Object PSCredential "domain\user",$securestring
tdewin
Veeam Software
 
Posts: 1043
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: SureReplica Custom Script to run chkdsk

Veeam Logoby CaptainFred » Thu Apr 24, 2014 3:32 pm

When SureBackup runs a custom script on a VM does it not run it under any credentials then? Not even the service accounts that it uses for backup/replication/VM indexing tasks?
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Next

Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 4 guests