Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Change environment
    • Sign In

    • State Not Answered
    • +1 person also asked this people also asked this
    • Replies 18 replies
    • Subscribers 71 subscribers
    • Views 785 views
    • Users 0 members are here
    • powershell
    • powershell_dab

    Change environment

    Amol Sonawane
    Offline Amol Sonawane 9 months ago

    Hi,

    I want to change the environment to folder which is containing the documents. There is cmdlet available however that is changing the environment to empty folders.

    Is there a way we can fix using the powershell?

    Thank you!

    Regards,

    Amol Sonawane 

    • Sign in to reply
    • Cancel

    Top Replies

    • Kevin van Haaren
      Offline Kevin van Haaren Tue, Oct 24 2023 5:20 PM in reply to Mike Madrid +1
      sounds like their are files in those folders that have attribute sheets setup. What happens if you uncomment the 2 $pwDocs lines, and change the -FolderPath on the Get-PWDocumentsBySearch to a -FolderID…
    Parents
    • Kevin van Haaren
      0 Offline Kevin van Haaren Mon, Feb 20 2023 5:02 PM

      Not in one shot. As long as any document has a row in the environment's document table the environment can't be changed. (Note that unless the environment has "create row in environment table" option turned on then documents won't have an entry in the environment's table until an attribute is assigned a value.

      If you are OK with blowing away all the current attribute data on your files you can use Remove-PWDocumentSheet to purge the existing attribute values and remove the document from the environment's document table in one go. This includes attributes assigned to file versions.

      Once you cleared the existing attribute sheets away you can reassign the environment with Set-PWEnvironmentByFolderPath

      So something like (this is off the top of my head and not verified code):

      $PathToClear = 'Path\To\PW\Folder'
      # Get all files & file versions in all sub folders
      $pwDocs = Get-PWDocumentsBySearch -FolderPath $PathToClear -GetVersionsToo
      $pwDocs | Remove-PWDocumentSheet
      
      # Now assign new environment
      Set-PWEnvironmentByFolderPath -FolderPath $PathToClear -Environment 'New Environment' -SubFolders
      

      If you want to move old attributes to new environment you'll have to get something that can export the existing attribute values, then tweak that to assign the values back into the new environment. I'm not seeing commands for this (but didn't dig real deep for it).

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Tomas Žukauskas
      0 Offline Tomas Žukauskas Mon, Oct 2 2023 7:55 AM in reply to Kevin van Haaren
      Kevin van Haaren said:
      As long as any document has a row in the environment's document table the environment can't be changed. (Note that unless the environment has "create row in environment table" option turned on then documents won't have an entry in the environment's table until an attribute is assigned a value

      Where do i check the "create row in environment table" option?

      I went through many random documents in various folders and could not find a single instance of Environment property being listed when using a command like this:

      $dox = Get-PWDocumentsBySearch -FolderPath $rootpath -Slow -GetAttributes
      
      $dox
      Also, i ran the following little script on my test projects and the Environment was successfully changed for all subfolders:
      $rootpath = 'company\name\region\project\'
      
      
      Write-Host "Retrieving sub-folders from $($rootpath)"
      
      $subfolders = Get-PWFolders -FolderPath $rootpath -PopulatePaths
      
      $masterEnv = 'Transmittals'
      
      foreach ($subfolder in $subfolders) {
          if ([string]::IsNullOrEmpty($subfolder.Environment)) {
             
              Set-PWFolderEnvironment -InputFolder $subfolder -NewEnvironment $masterEnv
          }
         
      }
      So, if the script did not return any errors and the Environment value was changed as expected, then i can safely assume that  the "create row in environment table" option is NOT turned on somewhere? And i can proceed with doing it on production projects? Or is it not so simple as i assume?
      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Dave Cole
      0 Offline Dave Cole Tue, Oct 3 2023 4:41 PM in reply to Tomas Žukauskas

      In the environment properties

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • MWBSI
      0 MWBSI Thu, Oct 19 2023 1:54 PM in reply to Dave Cole

      And this setting is per environment, not per folder.

      Mark Weisman | Bentley Systems

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • MWBSI
      0 MWBSI Thu, Oct 19 2023 1:54 PM in reply to Dave Cole

      And this setting is per environment, not per folder.

      Mark Weisman | Bentley Systems

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    No Data

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies