Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Convert system.string to .....
    • Sign In

    • State Verified Answer
    • Replies 6 replies
    • Subscribers 66 subscribers
    • Views 2009 views
    • Users 0 members are here

    Convert system.string to .....

    Luc Poulin
    Offline Luc Poulin over 3 years ago

    Cannot convert the "riler" value of type "System.String" to type "Bentley.ProjectWise.PowerShell.Common.User"

    I get this message when I try to create this

    $Users = Get-PWUsersByMatch | select-object name

    foreach ($User in $Users) {

    Get-PWUserSettingByUser -InputUsers $($User.name) -SettingName WorkDir_WhenUsingPWExplorer

    }

    In bold I try several variation but cannot fin dteh right coding...... y next step after that is to output to excel

    • Sign in to reply
    • Cancel

    Top Replies

    • Kevin van Haaren
      Offline Kevin van Haaren Fri, Dec 6 2019 5:56 PM in reply to Luc Poulin +1 verified
      oh, it's because of the select statment when creating $users. you're stripping out all the other properties. I missed that first time $users = Get-PWUsersByMatch foreach ($user in $users) { Get-PWUserSettingByUser…
    Parents
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 6 2019 5:30 PM

      Generally the pwps_dab parameters that start with -Input take the full object, not a part of it.  So just feed it $User

      Get-PWUserSettingByUser -InputUsers $User -SettingName WorkDir_WhenUsingPWExplorer

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Luc Poulin
      0 Offline Luc Poulin Fri, Dec 6 2019 5:52 PM in reply to Kevin van Haaren

      Same result

      Maybe my programmer skills still need to be polish :-)

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      +1 Offline Kevin van Haaren Fri, Dec 6 2019 5:56 PM in reply to Luc Poulin

      oh, it's because of the select statment when creating $users. you're stripping out all the other properties. I missed that first time

      $users = Get-PWUsersByMatch
      foreach ($user in $users) {
          Get-PWUserSettingByUser -InputUsers $user -SettingName WorkDir_WhenUsingPWExplorer
      }
      
      

       

      Answer Verified By: Luc Poulin 

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Reject Answer
      • Cancel
    • Luc Poulin
      0 Offline Luc Poulin Fri, Mar 6 2020 1:46 PM in reply to Kevin van Haaren

      Hello Kevin

      I try to apply the lesson from the previous code

      «...it's because of the select statment when creating $users. you're stripping out all the other properties...»

      I may have miss something.

      I got this to create a list

      $Users = Get-PWUsersByMatch

      And I also try ( just in case)

      $Users = Get-PWUsersByMatch | select-Object ID

      Then I try to create a foreach item in the list

      foreach ($User in $Users){

      $dr = $dt.NewRow()

      $dr.Name = Get-PWUsersByMatch -UserID $User | Select-Object Name (then I have the same message as before ***......)

      $dr.Description = Get-PWUsersByMatch -UserId $User | Select-Object Description

      $dr.Email = Get-PWUsersByMatch -UserId $User | Select-Object email

      $dt.Rows.Add($dr)

      }

      **** Get-PWUsersByMatch : Cannot bind parameter 'UserId'. Cannot convert the "Bentley.ProjectWise.PowerShell.Common.User" value of type

      "Bentley.ProjectWise.PowerShell.Common.User" to type "System.Int32".

      Any chance you can give a hand on this too?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Luc Poulin
      0 Offline Luc Poulin Fri, Mar 6 2020 1:46 PM in reply to Kevin van Haaren

      Hello Kevin

      I try to apply the lesson from the previous code

      «...it's because of the select statment when creating $users. you're stripping out all the other properties...»

      I may have miss something.

      I got this to create a list

      $Users = Get-PWUsersByMatch

      And I also try ( just in case)

      $Users = Get-PWUsersByMatch | select-Object ID

      Then I try to create a foreach item in the list

      foreach ($User in $Users){

      $dr = $dt.NewRow()

      $dr.Name = Get-PWUsersByMatch -UserID $User | Select-Object Name (then I have the same message as before ***......)

      $dr.Description = Get-PWUsersByMatch -UserId $User | Select-Object Description

      $dr.Email = Get-PWUsersByMatch -UserId $User | Select-Object email

      $dt.Rows.Add($dr)

      }

      **** Get-PWUsersByMatch : Cannot bind parameter 'UserId'. Cannot convert the "Bentley.ProjectWise.PowerShell.Common.User" value of type

      "Bentley.ProjectWise.PowerShell.Common.User" to type "System.Int32".

      Any chance you can give a hand on this too?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Mar 6 2020 2:37 PM in reply to Luc Poulin

      hmmm, I think you need a bit more info on objects and properties.

      In Powershell an object is a type of data. In this case user data. Objects have properties associatied with them. These properties are accessed via dot notation.

      of If you got data on one user:

      $user = Get-PWUsersByMatch -email 'user@example.com'

      and then just typed:

      $user

      you'd see the properties for that user:

      CreationDate     : 1/1/0001 12:00:00 AM
      LastLogin        :
      Description      : Example User
      Disabled         : False
      IsDisabled       : False
      Email            : user@example.com
      ID               : 1
      UserID           : 1
      IsConnected      : False
      Name             : user
      UserName         : user
      SecProvider      :
      Type             : Logical
      Identity         :
      IdentityProvider :

      So the value of $user.ID is an integer which is what Get-PWUsersByMatch -UserID expects

      However $user is still an object, not an integer. Additionally the Select statement creates a new object with just the selected properties, so:

      $user = Get-PWUsersByMatch -email 'user@example.com' | Select ID

      $user is still an object with a single property called ID. so

      Get-PWUsersByMatch -UserID $user

      fails because $user is an object, not an integer. $user.id the value of the property is an integer and would work.

      (when your Get-PWUsersByMatch returns multiple users they are grouped into an array and the foreach is just breaking the array up so you can work on individual users.

      Now, there are some tools in PowerShell that make what you're trying to do much easier. First, Select allows you to specify multiple properties to keep in one command. 2nd you can do many bulk commands on a group of an object without breaking them up in a foreach loop.

      So for what it appears you are trying to do you can smash it down into a single line:

      $dt = Get-PWUsersByMatch | Select Name,Description,Email

      $dt will now be an array of objects where each object has 3 properties: Name, Description and Email.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Luc Poulin
      0 Offline Luc Poulin Fri, Mar 6 2020 3:52 PM in reply to Kevin van Haaren

      Thank you....

      And I was hoping I was getting  my coding skills up one notch. Looks like it's more a little tiny fraction of a notch........

      Thank you again  Kevin, have a good weekend

      • 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