Array Setup and Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

Powershell Script to Create Clone, Mount Clone

SOLVED
Go to solution
smilerspeaking136
Occasional Contributor

Powershell Script to Create Clone, Mount Clone

G'Morning,

Does anyone have a script or point me in the right direction for the following script/tool.

## Microsoft OS requirement ##

  • Select a Volume Snap
  • Create a Clone
  • Mount Snap

With NetApp's Snapdrive - it is posisble to select a snapshot of a LUN and mount that at another drive letter.

I know this is all possible manually, just very tedious task when trying to restore data.

If not I'll work on it myself

Thanks

Sparkles

31 REPLIES
jrich52352
Trusted Contributor
Solution

Re: Powershell - create clone, mount clone

jrich523/NimblePowerShell · GitHub

whatever it doesnt do for you, let me know and i'll add it in.

smilerspeaking136
Occasional Contributor

Re: Powershell - create clone, mount clone

Awesome, thank you

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

Hi Justin, is there any documentation about what those scripts do and how to use them? Thanks. I'm looking for something similar as Mike asked but I'm no expert on power shell scripting.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

Sorry I have not had time to populate the docs. I've tried to create all of the functions in a very standard way.

If you tell me what you're trying to do i could provide the code you'd use.

Also I should in the next week or so have time to get back on top of this, I need to add "volume collections" and populate the docs and then i'll have the majority of the gui functionality implemented.

rfenton4
Honored Contributor

Re: Powershell - create clone, mount clone

Jason - there is a rather excellent introduction tutorial here

Many of the things Justin is using in his rather excellent scripts is also covered in that tutorial.

Hope this helps

Rich

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

basically I'm looking for scripts to make restoring data easier. Just like Mike said, clone a volume from a snapshot, give access permission of that volume to a server, connect to the volume using iSCSI in the server. Thanks.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

Those are all in the module, have you loaded it successfully?

You have to connect first, but you can get a list of all functions by running the following command.

gcm -Module nimble

That will return about 18 functions. the names are pretty self explanatory..

You can use tab to help complete things, for example if you do

get-nsvolume -<tab>

You can then tab through the different parameters.

I would suggest using powershell ISE to start since the intellisense will really help.

This was created in powershell 3 but should be compatible with  2, however i strongly suggest you use v3.

I've tried to add a good deal of protection to any remove command, but, like anything else, be careful with what you do.

in your case, are you talking about taking a snapshot that you have already and converting it in to a close and setting access? Is the snapshot from a protection plan?

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

Hi Justin, I tried the gcm –Module nimble command and it returns nothing. I copied all the scripts into my powershell profile and the folder is named nimble. I’m running Windows 8 which is powershell version 4. Does that matter? Thanks.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

so you'll want to copy all of the files (and unblock them) to

my documents\windowspowershell\modules\nimble

dump all the files in that folder and then from powershell type

import-module nimble

gcm -module nimble

also, V4 is currently only with Windows 2012 R2 and as a CTP download. however if you do have it, it will work fine.

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

I did try the import command and here’s what I got:

Import-Module : Could not load file or assembly

'file:///C:\Users\admin\Documents\WindowsPowerShell\Modules\nimble\GroupMgmt.dll' or one of its dependencies. Operation

is not supported. (Exception from HRESULT: 0x80131515)

At line:1 char:1

+ Import-Module nimble

+ ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: ( , FileLoadException

    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

this is from the Win8 box?

if you type in $host what do you get? It should say its V3. if its V2 then its possible that the groupmgmt.dll might be compiled for .net 4.0 and since powershell V2 is .net 2.0 that might cause an issue.

also did you unblock the files? that might also cause it

you can do, in V3

gci "$(split-path $profile)\modules\nimble" -r | Unblock-File

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

That was on a Windows server 2012 datacenter which has version 3. I confirmed it by running get-host command. The files have been unblocked too.

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

One thing I noticed is you said groupmgmt.dll might be compiled for .net 4.0 but I only have 4.5 on my Windows 8 and Windows server 2012. That might causing the issue?

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

try doing this, go to the folder that contains the files (nimble folder) and type this

add-type -Path .\GroupMgmt.dll

also, im not sure if this matters,but do you run it elevated? i have mine set to by default.

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

Thanks Justin. Running add-type command fixed the problem.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

Thats kind of odd since essentially thats what the import-module is doing.

smilerspeaking136
Occasional Contributor

Re: Powershell - create clone, mount clone

I did stumble across this yesterday - after getting wound up using disk part, new PS modules should be able to cover the requirements for disk part when mounting a clone.

http://swodniw.wordpress.com/2012/10/12/powershell-cmdlets-one-by-one-or-how-to-replace-diskpart-with-powershell/

I'll be looking into this in a week or so.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

yeah 2012 is awesome with its cmdlets... we're making a push to get to 2012 for this reason. however you can feed stuff to diskpart fairly easily..

$id = gwmi win32_diskdrive -ComputerName $ComputerName -Credential $Credential -Filter "model LIKE 'vmware%'" | sort @{e={(($_.size /1gb) / $size)%1}},index -Descending |select -first 1 -exp index

$dpscript = @"

select disk $id

online disk noerr

convert gpt noerr

create partition primary noerr

assign letter=$letter

FORMAT FS=NTFS UNIT=64k QUICK Label=SQL

"@

$job = Invoke-Command -ScriptBlock {$args[0] | diskpart} -Session $session -ArgumentList $dpscript

I use this as part of my Add-DriveToVm

smilerspeaking136
Occasional Contributor

Re: Powershell - create clone, mount clone

I've just got the following to work - (Remove "write-host" from the "foreach" line **or leave in to see what its going to do **):

### get Nimble disks ###

$nimbledisks = get-disk | Where {$_.Manufacturer -like "Nimble*"} | select -expandproperty "number"

### Remove readonly ###

write-host "remove readonly atribute from disks > $nimbledisks" -foregroundcolor yellow

foreach( $disk in $nimbledisks ){ write-host set-disk -number $disk -isreadonly 0}

write-host "Disks > $nimbledisks -> writeable" -foregroundcolor green

### Remove offline ###

write-host "remove offline atribute from disks > $nimbledisks"  -foregroundcolor yellow

foreach( $disk in $nimbledisks ){ write-host set-disk -number $disk -isoffline 0}

write-host "Disks > $nimbledisks -> online" -foregroundcolor green

onlinedisks.PNG.png

Next I need to work out assigning drive letters, holiday first though

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

for 2012 here is what i do, this will grab all "raw" disks, meaning anything that isnt used. this does make an assumption of only a single raw disk, but as you've shown its fairly easy to foreach it.

$disk = get-disk  | ? partitionstyle -eq "RAW"

set-disk -InputObject $disk -IsOffline $false

set-disk -InputObject $disk -IsReadOnly $false

Initialize-Disk -InputObject $disk -PartitionStyle MBR

New-Partition -InputObject $disk -UseMaximumSize -DriveLetter $letter

Format-Volume -DriveLetter $letter -FileSystem NTFS -NewFileSystemLabel "data" -Confirm:$false

also, to find the next valid letter...

$volumes = gwmi win32_volume

$letters = $volumes | ? {$_.driveletter} |  select -exp driveletter | sort | %{$_.replace(":","")}

$letter = [string][char]([char]'C'..[char]'Z' | ? {[char]$_ -notin $letters} | select -first 1)

aherbert23
Trusted Contributor

Re: Powershell - create clone, mount clone

I noticed that Justin Rich is using the same GroupMgmt.dll that I made. I have a script that does something similar to the original request but for SQL servers. It could easily be modified to be used for any other such scenario. It also handles all the diskpart and chkdsk needs. I have a couple of customers that use this today for refreshing Dev/Test and reporting SQL servers.

https://dl.dropboxusercontent.com/u/17785549/nimbleScripts.zip

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

Hi Adam, thanks. those are very good scripts. I’ll see if I can customize them according to my need. I’ll probably spend some time on improving my PS script skill first ☺

jliu79
Frequent Advisor

Re: Powershell - create clone, mount clone

Hi Justin, can you give me an example of the new-nsclone command? I couldn’t figure out how to use it. Thanks.

jrich52352
Trusted Contributor

Re: Powershell - create clone, mount clone

Looks like i havent fully implemented that part yet. let me take a look and see if i can get it going easily.