PowerShell Script for Copy Vault

Hello All,


We have two vaults - production and development.
Both vault use SQL DB
From time to time we create copy from the production vault through the admin panel.
Has anyone tried to create a PowerShell script for this operation or have script example?
I appreciate any help.

P.S. I know this question was asked two year ago but except two (CopyVaultJob and  CopyVault) the reference to manual we did not received any answers.

Parents Reply Children
  • As I understand it, I have to create a copy vault and define what I want to copy and what are PD's ,
    and for the target vault I must specify all the parameters that are specified in the documentation.
    Finaly, CopyVaultJob will include source vault with all PD's for copy and CopyVaultOutputInfo will contain definition for target vault.

  • Yes, but you pass in a "CopyVault" instance - which your code is already creating and populating - then you call CopyVault and it returns you a CopyVaultOutputInfo instance.  You don't create the CopyVaultOutoutInfo instance.

  • Hello Craig,

    Thank you for answer.

    It's looks i move to the right direction.

    I'm passing  VaultProperties  with CopyVaultJob and it is looks like working (as you can see in screenshot) but nothing doesn't happen.Script is running but line 

    $server.VaultManagementOperations.CopyVault($copyVaultJob) 

    Don't working or working and I don't see any result

    #Source vault Definition for Copy (Prod Vault)

    $copyVaultJob = new-object MFilesAPI.CopyVaultJobClass
    $copyVaultJob.CopyflagAllExceptData = $true
    $copyVaultJob.VaultGUID = "{EDE7D088-6817-425A-B59E-D48570AE51CC}"


    #Target Vault definiton for copy (Dev Vault)

    $copyVaultJob.VaultProperties.DisplayName = "Dev_Vault"
    $copyVaultJob.VaultProperties.AdvancedEventLog = $false
    $copyVaultJob.VaultProperties.EncryptionOfFileDataAtRest = $false
    $copyVaultJob.VaultProperties.ExtendedMetadataDrivenPermissions =$false
    $copyVaultJob.VaultProperties.FileDataConnectionString = $null
    $copyVaultJob.VaultProperties.FileDataStorageType = 0
    $copyVaultJob.VaultProperties.FullTextSearchLanguage = "eng"
    #$destVaultProperty.SQLDatabase <---- next time

    $iconPath = 'C:\Users\bvainrub\Pictures\Icons\ICONS\vault.ico'
    # Read the icon file as bytes
    $iconBytes = [System.IO.File]::ReadAllBytes($iconPath)
    # Assign the byte array to the Icon property
    $copyVaultJob.VaultProperties.Icon = $iconBytes

    $copyVaultJob.VaultProperties.MainDataFolder = "C:\Program Files\M-Files\Server Vaults\"
    $copyVaultJob.VaultProperties.VaultGUID = [GUID]::NewGuid().ToString()

    Write-Host "New GUID :"$copyVaultJob.VaultGUID "For Vault" $copyVaultJob.DisplayName


    Write-Host "Creating Vault..." $copyVaultJob.VaultProperties.DisplayName


     $server.VaultManagementOperations.CopyVault($copyVaultJob)


    Write-Host "Completed"

  • How long have you left this?  Copying a vault can take some time.

  • I can't see any open API issues related to this method.  Some questions:

    • Do you have any exception trapping earlier or later which may be affecting this?
    • How large is the source vault (database and files)?
    • Are you sure that the various parameters are correct on your copy job?
    • If you do the same from another language do you see this?
    • What version of PowerShell, and what version of M-Files?
  • HI Craig,

    Do you have any exception trapping earlier or later which may be affecting this?
    No just promt after each important step in the script
    Write-Host "what is done"

    How large is the source vault (database and files)?
    All together :  63.9 MB (67,050,431 bytes)

    Are you sure that the various parameters are correct on your copy job?
    No,I did not find how to define Firebird DB. I just assume M-Files take Firebird like default DB.
    SQL DB I did not configured and line is commented:
    #$destVaultProperty.SQLDatabase <---- next time

    If you do the same from another language do you see this?
    I did it in english and french same results.


    What version of PowerShell, and what version of M-Files?
    Major  Minor  Build   Revision
    -----  ----- ----- ------------------
    5           1      22621    2506

  • Re: language I meant C# or other programming language outside of Powershell. I ask because I know some people have had PS-specific issues.

    Also: what version of powershell and what version of M-Files? 

  • M-Files version 23.11.13168.7

    $PSVersionTable.PSVersion     PS Version : 5.1..22621

    I did not try any other programming language.

  • I have replicated this issue and found an older tracker item related to it with ID 129320.

    It appears that some methods in the COM API are not callable from within PowerShell.  This is to do with how the data is passed between PowerShell and M-Files itself.  CopyVault appears to be one such affected method.

    At the moment it appears that the only workaround is to use a different environment (e.g. C#) to run such scripts, as these pass data through to M-Files in the expected manner.