Page 1 of 1
Cannot create snapshot via powershell
Posted: Mon Mar 05, 2018 3:39 am
by chell
Hi
I'm trying to use the create snapshot via the sample powershell script.
I keep getting the error "External component has thrown an exception"
The script is connecting to the star wind server and if I # out the new-snapshot command it does list all of the snapshots current there, so the device name is correct.
Starwind 8.0.0.11818
Any ideas?
Is mounting a snapshot via powershell possible yet?
Thanks
Code: Select all
Import-Module StarWindX
$server = New-SWServer -host 192.168.12.1 -port 3261 -user root -password starwind
try
{
#Connection
$server.Connect()
if ( $server.Connected )
{
$deviceName = "lsfs4"
#
# Create snapshot
#
New-Snapshot $server $deviceName "snapshotName1" "snapshotDescription"
Write-Host "Snapshot created!" -foreground yellow
Write-Host ""
#
# get snapshots list
#
foreach($device in $server.Devices)
{
if ( $device.name -eq $deviceName)
{
if ( $device.IsSnapshotsSupported )
{
foreach($snapshot in $device.Snapshots)
{
Write-Host "Snapshot Id: $($snapshot.Id) Name: $($snapshot.name) Date: $($snapshot.Date)"
}
}
break;
}
}
}
$server.Disconnect()
}
catch
{
Write-Host "Exception $($_.Exception.Message)" -foreground red
$server.Disconnect()
}
Re: Cannot create snapshot via powershell
Posted: Tue Mar 06, 2018 10:40 am
by Oleg(staff)
Hi chell,
Is mounting a snapshot via powershell possible yet?
No, this option is not available via PowerShell at the current, 8.0.0.11818 build, yet.
Re: Cannot create snapshot via powershell
Posted: Thu Mar 08, 2018 3:23 am
by chell
Feature request. The ability to roll back to a snapshot would be really useful.
Mounting a snapshot is handy if you want to copy a few files. but its extremely time consuming if you need to copy a large amount of data.
For example a ransomware attack. I would revert the drive back to the last snapshot then use the backups to restore the changes. This would be much quicker than restoring all of the data from backups or copying data from a mounted snapshot
Re: Cannot create snapshot via powershell
Posted: Thu Mar 08, 2018 10:33 am
by Oleg(staff)
Yes, I have already sent your request to our R&D team. This feature will be added in the further StarWind builds.
Re: Cannot create snapshot via powershell
Posted: Thu Mar 08, 2018 1:07 pm
by Sekkmer
I run into the same problem with the current build (11818) but if you run the script on the previous build (11456) it is working fine even if the server is running with (11818)
regarding the mounting of a snapshot, you should look into the original script which can be found here:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\StarWindX\LSFS.ps1
you just need to write a script which creates the same LSFSDevice as the original then you just add these parameters before the creation:
(device.File does not work in 11456 for LSFSDevices, use device.GetPropertyValue("DataPath"))
$param.AppendParam("DataPath", device.File);
$param.AppendParam("SnapshotID", snapshot.Offset);
$param.AppendParam("SnapshotDisabled", "yes");
Edit:
I just tested that you can create a snapshot in build 11818 with server.ExecuteCommand(STARWIND_COMMAND_TYPE.STARWIND_COMMAND, "CreateSnapshot", param).
For this to work add the following parameters:
$param.AppendParam("deviceID", device.DeviceId);
$param.AppendParam("snapshotName", "Name Of Your New Snapshot");
you can add an additional parameter: "snapshotDescription"
Re: Cannot create snapshot via powershell
Posted: Fri Mar 09, 2018 10:38 am
by Oleg(staff)
It should work.
Let the community know if it works for you.
Re: Cannot create snapshot via powershell
Posted: Tue Mar 13, 2018 6:56 pm
by chell
Hi Sekkmer
Thank you for your reply.
Is it possible for you to post a copy of your test script? I'm having troubles changing the script above to work with server.ExecuteCommand(STARWIND_COMMAND_TYPE.STARWIND_COMMAND, "CreateSnapshot", param)
much appreciated
Sekkmer wrote:I run into the same problem with the current build (11818) but if you run the script on the previous build (11456) it is working fine even if the server is running with (11818)
regarding the mounting of a snapshot, you should look into the original script which can be found here:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\StarWindX\LSFS.ps1
you just need to write a script which creates the same LSFSDevice as the original then you just add these parameters before the creation:
(device.File does not work in 11456 for LSFSDevices, use device.GetPropertyValue("DataPath"))
$param.AppendParam("DataPath", device.File);
$param.AppendParam("SnapshotID", snapshot.Offset);
$param.AppendParam("SnapshotDisabled", "yes");
Edit:
I just tested that you can create a snapshot in build 11818 with server.ExecuteCommand(STARWIND_COMMAND_TYPE.STARWIND_COMMAND, "CreateSnapshot", param).
For this to work add the following parameters:
$param.AppendParam("deviceID", device.DeviceId);
$param.AppendParam("snapshotName", "Name Of Your New Snapshot");
you can add an additional parameter: "snapshotDescription"
Re: Cannot create snapshot via powershell
Posted: Thu Mar 15, 2018 12:08 pm
by Sekkmer
the line should have been: " $server.ExecuteCommand(0, "CreateSnapshot", $params)", I use C# for my StarWind project and I just copied the line from there.
I wrote the script for you:
Code: Select all
function New-SnapshotFixed( [parameter(Mandatory=$true, HelpMessage="StarWind server object", Position=0)]
[ValidateNotNullOrEmpty()]
$server,
[parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
$deviceName,
[parameter(Mandatory=$true, Position=2)]
[System.String]$snapshotName,
[parameter(Mandatory=$false, Position=3)]
[System.String]$snapshotDescription )
{
if( !$server.Connected )
{
$server.Connect()
}
$device = Get-Device $server -name $deviceName
if ( !$device )
{
throw "Device with specified name not found"
}
if ( $device.IsSnapshotsSupported )
{
$params = new-object -ComObject StarWindX.Parameters
$params.AppendParam("deviceID", $device.DeviceId)
$params.AppendParam("snapshotName", $snapshotName)
$params.AppendParam("snapshotDescription", $snapshotDescription)
$server.ExecuteCommand(0, "CreateSnapshot", $params)
}
else
{
throw "Device doesn't support snapshots"
}
}
Re: Cannot create snapshot via powershell
Posted: Sun Mar 18, 2018 3:07 am
by chell

Thank you very much Sekkmer. I'll give it a go.
Re: Cannot create snapshot via powershell
Posted: Mon Mar 19, 2018 10:38 am
by Boris (staff)
chell,
Whenever you try that, feel free to update the community with your experience.