PowerShell script exchange
Post Reply
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

SureReplica Custom Script to run chkdsk

Post by CaptainFred »

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
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by nefes »

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.
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

Ok great, any chance you give me a starting point, I have no idea how to "call chkdsk remotely and parse it's output" ?!
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by nefes »

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
}
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

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.
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by nefes »

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

Re: SureReplica Custom Script to run chkdsk

Post by veremin »

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.
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

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

Re: SureReplica Custom Script to run chkdsk

Post by veremin »

Do I just point it directly to a ps1 file?
Correct.
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

ok, do I need to use %vm_ip% then instead?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by veremin »

It seems that you can disregard "argument" section, as the script itself has the part responsible for connecting to the given VM. Thanks.
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by tdewin »

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
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

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?
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by tdewin »

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
CaptainFred
Enthusiast
Posts: 88
Liked: 2 times
Joined: Jul 31, 2013 12:05 pm
Full Name: Si
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by CaptainFred »

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?
s.weis
Novice
Posts: 3
Liked: never
Joined: Jun 17, 2015 6:47 am
Contact:

[MERGED] : CHKDSK.exe script for SureBackup

Post by s.weis »

Hello,

I want to use chkdsk.exe in order to check our backups with SureBackup. I am new in this topic. Is there any script template?

Thank You,
Stephan
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by veremin »

Hi, Stephan,

Check the examples provided above and see whether they answer your requirements.

Thanks.
lukejf
Enthusiast
Posts: 66
Liked: 5 times
Joined: Jul 10, 2012 8:15 am
Full Name: Luke
Contact:

Re: SureReplica Custom Script to run chkdsk

Post by lukejf »

Hey Guys
Sorry to bring up this thread again however i think it is relevant due to all the CBT errors that have been coming up in vmware. I have started working on a powershell / WMI script to test logical drives for corruption however I'm finding WMI often craps out before it finishes due to some sort of wmi limitation.
Just wondering how you guys are managing to run a chkdsk during a surebackup job
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests