Box CLI with Powershell: How do I wait or check until "operation_blocked_temporary" is gone?

新規投稿

コメント

1件のコメント

  • mboggs

    So I think I've figured a way to do this, but it doesn't use the error message. I have no idea if this is efficient, but it works. Note: I'm still testing this, so I'll update if it fails. 

     

    The logic:

    1. Grab the folder your are moving's (source folder) parent ID. (box folders:get)
    2. Try the move (Box Folders:Move)
    3. Grab the source folder's parent ID again. (box folders:get)
    4. Check if the parent ID now equals the destination folder ID. (Do/Until)
      1. If not, pause for a while and try again. (start-sleep)
      2. If it does, then your move was successful and you can move on. 

     

    The code example: 

    #get the parent ID of the source folder for the do until loop
    $FolderInfo = box folders:get $sourceFolder --as-user=$user --json | ConvertFrom-Json
    $parentIDofFolder = $FolderInfo.parent.id        
            
    DO
    {         
        #Try the move
        box folders:move $sourceFolder $destinationParentFolder --as-user=$user
        #Get the parent ID of the folder to see if it moved. If it doesn't match the "destination" location, then it failed. 
        $FolderInfo = box folders:get $sourceFolder --as-user=$user --json | ConvertFrom-Json
        $parentIDofFolder = $FolderInfo.parent.id
        Write-Output "ParentID: $parentIDofFolder, ParentID of Destination folder: $destinationParentFolder"
        If ($parentIDofFolder -eq $destinationParentFolder) {
        Write-Output "Move complete" 
        } Else {
                Write-Output "Parent ID did not change. Need to try again. current parentid: $parentIDofFolder. Pausing for 10 min then trying again"
                Write-Output (get-date).ToString('T')
                #pause for 10 min. 
                Start-Sleep -s 600
        }
    } Until ($parentIDofFolder -eq $destinationParentFolder)        

      

     

    Note: I'm a BOX CLI and Powershell amateur at best. Accepting all critic and suggestions. 

    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。