Sharepoint 2013 designer and powershell


  • Hi,

    i am starting a powershell script inside a workflow that starts automatically when item is created.

    it basically moves the attachment of a list item to a document library.

    i am having a weird issue. When the workflow starts automatically it fails but when i start it manually on the item it works.

    I have determined that the powershell script at one point basically opens the document to get its data and then saves it to new place. So when i start the workflow manually it works because it is using my PC resources. But when the workflow stats automatically it fails. Does anyone have an idea how to get it to work automatically? Powershell script below:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    $WebURL = "http://intranet/sites/test/"
    $SourceListName = "agreement_list"
    $TargetLibraryName = "agreement"
    $fileAttachmentUrl = $var3
    $web = Get-SPWeb $WebURL
    $SourceList = $web.Lists[$SourceListName]
    $TargetLibrary = $web.Lists[$TargetLibraryName]
    #Get the List file
    $file = $web.GetFile($var3)
    $bytes = $file.OpenBinary()
    $TargetFileName = $TargetLibrary.RootFolder.Url+"/"+$var2
    $TargetFile = $TargetLibrary.RootFolder.Files.Add($TargetFileName, $bytes, $true)

    The error i get when it starts automatically is related to the $bytes = $file.OpenBinary(), (probably because it opens the file using the computer that manually starts the script) error is:

    Error while executing PowerShell Script: Exception calling "OpenBinary" with "0" argument(s): ""

    • Modifié Fazzzer mercredi 16 mai 2018 13:31
    mercredi 16 mai 2018 10:06


Toutes les réponses