Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Is there a PowerShell command to set "Global view assigned to folder"
    • Sign In

    • State Suggested Answer
    • +1 person also asked this people also asked this
    • Replies 11 replies
    • Answers 1 answer
    • Subscribers 66 subscribers
    • Views 4000 views
    • Users 0 members are here

    Is there a PowerShell command to set "Global view assigned to folder"

    DaveSime
    Offline DaveSime over 5 years ago

    Would like to run a query to get a list of folders by Name then apply a view to be the  "Global view assigned to folder"

    • Sign in to reply
    • Cancel

    Top Replies

    • DaveSime
      Offline DaveSime Thu, Nov 16 2017 3:54 PM +1
      Looks like this will work $PLSfolders = get-pwfolders -folderpath "SUBTRAN\TRANS" -Slow | where-object -Property "Name" -Like -Value "PLS" $PLSfolders | foreach-object -Process {Set-PWFolderView…
    • Kevin van Haaren
      Offline Kevin van Haaren Fri, Dec 15 2017 11:28 AM in reply to Erik Holmqvist +1
      Import-Module -Name "C:\Program Files (x86)\Bentley\ProjectWise\bin\PowerShell\PWPS_DAB\PWPS_DAB.dll" -Verbose -Force this won't work with the latest module, the path has changed. I'd switch to: Import…
    • Kevin van Haaren
      Offline Kevin van Haaren Fri, Dec 15 2017 11:31 AM in reply to Erik Holmqvist +1
      Also, storing the plain text password in the script is bad security. I prefer using single sign-on for most of my scripts that run interactively. Or you can use the -UseGui option on New-PWLogin to prompt…
    Parents
    • DaveSime
      0 Offline DaveSime Thu, Nov 16 2017 3:54 PM
      Looks like this will work
       
      $PLSfolders = get-pwfolders -folderpath "SUBTRAN\TRANS" -Slow | where-object -Property "Name" -Like -Value "PLS"
      $PLSfolders | foreach-object -Process {Set-PWFolderView -InputFolder $PSItem.ProjectGUID -View "Trans Model Report"}
       
      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Erik Holmqvist
      0 Offline Erik Holmqvist Wed, Dec 13 2017 10:34 AM in reply to DaveSime

      ## IMPORT PWPS_DAB.DLL
      Import-Module -Name "PWPS_DAB" -DisableNameChecking
      
      ## Choose folder and its subfolder which it searching in
      $TargetFolder = "Folder/Subfolder"
      
      ## Specify which folder that you want to change view
      $ThisFolder = "Documents"
      
      ## Choose which view you want to change to
      $ThisView = "MyView"
      
      ############################################ SCRIPT ############################################################
      New-PWLogin -UseGui 
      $Folders = get-pwfolders -folderpath $TargetFolder -Slow | where-object -Property "Name" -Like -Value $ThisFolder
      $Folders | Set-PWFolderView -View $ThisView
      ############################################ SCRIPT ############################################################
      
      ## Logging out
      Undo-PWLogin

      Thanks Dave this saved me alot of time! Took a while for me to figure out how to make use of your code, so my gonna post my whole script here for newbies like me :) 

      Would also be able to change the "Preview pane view" anyone have a clue how to do that? 

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 15 2017 11:28 AM in reply to Erik Holmqvist

      Import-Module -Name "C:\Program Files (x86)\Bentley\ProjectWise\bin\PowerShell\PWPS_DAB\PWPS_DAB.dll" -Verbose -Force

      this won't work with the latest module, the path has changed. I'd switch to:

      Import-Module -Name "PWPS_DAB" -DisableNameChecking

      I've not found -Force necessary. -DisableNameChecking turns off the warning message about unsupported verbs.

       

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 15 2017 11:31 AM in reply to Erik Holmqvist

      Also, storing the plain text password in the script is bad security. I prefer using single sign-on for most of my scripts that run interactively. Or you can use the -UseGui option on New-PWLogin to prompt for a login that uses secure string.

      If you need to automate the script store the securestring version of the password in the script, not the plaintext.

       

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Erik Holmqvist
      0 Offline Erik Holmqvist Fri, Dec 15 2017 11:46 AM in reply to Kevin van Haaren

      Good feedback Kevin!

      Have edit my script above according to your comments.

      How about the Preview pane view? Is it possible to change that?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 15 2017 3:44 PM in reply to Erik Holmqvist

      I can't find a way to set the Preview pane view. Would be nice.

      I did spot another issue with your script, one that will make it pretty slow if you process a lot of folders.  You do:

      $Folders | foreach-object -Process {Set-PWFolderView -InputFolder $Folders.ProjectGUID -View $ThisView}

      your foreach-object is using $Folders.ProjectGUID. That is an array of all the folders already (you can just print it by doing $Folders.ProjectGUID and see what it lists). So for each item of the $Folders array you're setting the view on all the items in $Folders. In other words you're setting the view $Folders.count * $Folder.count times. For 1000 folders you would be setting the view over and over again, 1,000,000 times.

      There are several different ways to handle this scenario. I'm partial to number 3 below as it hands the complicated stuff off to the function.

      # use the $_ automatic variable to refer to the current item
      $Folders | Foreach-Object -Process { Set-PWFolderView -InputFolder $_.ProjectGUID -View $ThisView }
      
      # explicitly define a variable to use for each item
      ForEach-Object ($f in $folders) {
          Set-PWFolderView -InputFolder $f -View $ThisView
      }
      
      # The help indicates Set-PWFolderView accepts an array of folders to operat on,
      # so we can let it handle the foreach loop
      $Folders | Set-PWFolderView -View $ThisView
      

      The trick to seeing this in the help is:

      SYNTAX
      Set-PWFolderView [-InputFolder] <ProjectWiseFolder[]> [-View] <string> [<CommonParameters>]

      The syntax defines the -InputFolder accepts an item of type ProjectWiseFolder and the [] means it accepts a whole list of them and it will operate on each individual item. You don't have to manually break out the ProjectGUID because it says it accepts the ProjectWiseFolder type. If it just wanted the GUID it would say something like <ProjectGUID[]> instead

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 15 2017 3:44 PM in reply to Erik Holmqvist

      I can't find a way to set the Preview pane view. Would be nice.

      I did spot another issue with your script, one that will make it pretty slow if you process a lot of folders.  You do:

      $Folders | foreach-object -Process {Set-PWFolderView -InputFolder $Folders.ProjectGUID -View $ThisView}

      your foreach-object is using $Folders.ProjectGUID. That is an array of all the folders already (you can just print it by doing $Folders.ProjectGUID and see what it lists). So for each item of the $Folders array you're setting the view on all the items in $Folders. In other words you're setting the view $Folders.count * $Folder.count times. For 1000 folders you would be setting the view over and over again, 1,000,000 times.

      There are several different ways to handle this scenario. I'm partial to number 3 below as it hands the complicated stuff off to the function.

      # use the $_ automatic variable to refer to the current item
      $Folders | Foreach-Object -Process { Set-PWFolderView -InputFolder $_.ProjectGUID -View $ThisView }
      
      # explicitly define a variable to use for each item
      ForEach-Object ($f in $folders) {
          Set-PWFolderView -InputFolder $f -View $ThisView
      }
      
      # The help indicates Set-PWFolderView accepts an array of folders to operat on,
      # so we can let it handle the foreach loop
      $Folders | Set-PWFolderView -View $ThisView
      

      The trick to seeing this in the help is:

      SYNTAX
      Set-PWFolderView [-InputFolder] <ProjectWiseFolder[]> [-View] <string> [<CommonParameters>]

      The syntax defines the -InputFolder accepts an item of type ProjectWiseFolder and the [] means it accepts a whole list of them and it will operate on each individual item. You don't have to manually break out the ProjectGUID because it says it accepts the ProjectWiseFolder type. If it just wanted the GUID it would say something like <ProjectGUID[]> instead

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    • Erik Holmqvist
      0 Offline Erik Holmqvist Mon, Dec 18 2017 12:09 PM in reply to Kevin van Haaren

      Good information again Kevin! Changed the script above once more :) 

      Tried to figure out what this operator means | but google didn't give me any good answer.


      It would indeed be nice to change the Preview pane view. Have about 200 Folders I need to change the preview pane on, I'll guess I do it manually for now. 

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Tue, Dec 19 2017 12:25 AM in reply to Erik Holmqvist

      | is a pipe operator, it originated in the UNIX world where it meant "send all the text output from one command to the next command". Powershell adopted the operator and expanded it to mean "send all the objects from one item to the next"

      so $Folders | Set-PWFolderView -View $ThisView

      means:

      take all the objects stored in $Folders variable and pipe them into the Set-PWFolderView. Set-PWFolderView is expecting one or more ProjectWiseFolder objects so it checks what you've sent it, and when it sees it's got ProjectWiseFolders it does the same operation on each item it is sent.

      You could've piped the whole Get-PWFolders straight into the Set-PWFolderView, but I actually prefer saving those items into a variable like you're doing here. Helps if I need to troubleshoot stuff in the future or need to do another set of operations on the same folders.

      More on pipes:

      www.tomsitpro.com/.../powershell-piping-filtering-objects,2-771.html

       

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

    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