Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-QlikUser is not working #133

Closed
devparashar88 opened this issue Sep 30, 2020 · 19 comments
Closed

Update-QlikUser is not working #133

devparashar88 opened this issue Sep 30, 2020 · 19 comments

Comments

@devparashar88
Copy link

devparashar88 commented Sep 30, 2020

Hi All
Update-QlikUser is not updating the value when I import the values from csv(delimiter is ,) .I have two column in csv userid & custom property

Userid, Customproperty
1234, StreamReadManagement=testread

There is only one custom property already exist for this user (StreamWriteManagement=testwrite)

after appending the string returned is StreamReadManagement=testreadStreamWriteManagement=testwrite which is not accepted by Update-QlikUser.
since it accepts the values in StreamReadManagement=testread StreamWriteManagement=testwrite
any help is much appreciated

@Nillth
Copy link
Collaborator

Nillth commented Oct 4, 2020

The following will import the CSV file.
It will find the user with the matching UserID.
It will then update the custom property value for that user.
(Optionally, uncomment to only append the value to the user)

The Values that you are applying to the user must exist in the Custom Property Definition.
If they are not in the custom property definition you will need to add them.

$CSVUsers = Get-Content .\Documents\GitHub-Qlik-Cli-Windows_Issue_133.csv|ConvertFrom-Csv
Connect-Qlik -TrustAllCerts

#region update Missing Custom Property Values
##Update the Custom Property if a value is missing.
$UCP = $CSVUsers.Customproperty|Select -Unique
$UCPNames = $UCP|%{$($_ -split "=")[0]}|select -Unique
foreach($UCPName in $UCPNames){
    $Changes = $false
    $Values = $UCP|?{$_.StartsWith("$($UCPName)=")}|%{$($_ -split "=")[1]}
    $QSCustomProperty = Get-QlikCustomProperty -filter "Name eq '$($UCPName)'" -full
    $Values|%{
        if (!($_ -in $QSCustomProperty.choiceValues)){
            $QSCustomProperty.choiceValues += $_
            $Changes=$true
        }
    }
    if ($Changes -eq $true){
        $QSCustomProperty = Update-QlikCustomProperty -id $QSCustomProperty.id -choiceValues $QSCustomProperty.choiceValues
    }
}
#endregion update Missing Custom Property Values

#region update User object
foreach ($CSVUser in $CSVUsers){

    $QSUser = Get-QlikUser -filter "UserID eq '$($CSVUser.UserId)'" -full
    if ($null -eq $QSUser){Write-Warning "User with ID $($CSVUser.UserId) Doest Not Exist"}else{
    [string[]]$customProperties = ""
    <<# #Include the next line to maintain existing properties, exclude it to only include value from CSV.
    [string[]]$customProperties = $($QSUser.customProperties|%{"$($_.definition.Name)=$($_.value)"})
    #>
    $customProperties += $CSVUser.Customproperty
    Update-QlikUser -id $QSUser.id -customProperties $customProperties
    }
}
#endregion update User object

@devparashar88
Copy link
Author

Thanks a lot @Nillth for helping .

@kumaribabita
Copy link

Hi All,
This was really helpful on updating Custom Property values.
Is there any way we can delete Custom Property values?

@Nillth
Copy link
Collaborator

Nillth commented Jun 9, 2021

From the Custom Property Definition? or from the applied values on a object?

@kumaribabita
Copy link

Let me give an example here-
Suppose there is user who have values assigned as CustomPropertyName ='xyz','abc','def'. Can we delete value ='xyz'?

This we have to do for around 700 users.

@izak004
Copy link

izak004 commented Aug 16, 2022

Hi @Nillth ,
I have a simple question, and I am sorry I can't figure out -
What is the csv file name, and column name's in your code? so that I can modify accordingly.

@Nillth
Copy link
Collaborator

Nillth commented Aug 17, 2022

What is the csv file name, and column name's in your code?

as per the original request the column names are the same

Userid, Customproperty

and for the file name
its on the first line GitHub-Qlik-Cli-Windows_Issue_133.csv

$CSVUsers = Get-Content .\Documents\GitHub-Qlik-Cli-Windows_Issue_133.csv|ConvertFrom-Csv

throughout the code you can see references to the Properties imported from the CSV

$CSVUser.UserId
$CSVUsers.Customproperty

@izak004
Copy link

izak004 commented Aug 30, 2022

Thanks @Nillth for your response.

I get this error when I use the above code. Can you please assist?
I used the same names for the file, the columns and customproperty.

Update-QlikUser : Cannot process argument transformation on parameter 'id'. Cannot convert value to type System.String.
At line:34 char:25

  • Update-QlikUser -id $QSUser.id -customProperties $customPropertie ...
    
  •                     ~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Update-QlikUser], ParameterBindingArgumentTransformationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,Update-QlikUser

    The code at line 34 is
    Update-QlikUser -id $QSUser.id -customProperties $customProperties

@izak004
Copy link

izak004 commented Aug 30, 2022

Hi @Nillth ,

image

@izak004
Copy link

izak004 commented Aug 30, 2022

also, what happens if there are two same ID's, but from different domains but belonging to the same person.

@izak004
Copy link

izak004 commented Sep 14, 2022

Hello @Nillth or anyone who could assist :)

I am unable to figure out how to fix this error, and would appreciate your help. The issue seems to be with the ID. I get an error when I do the Print, but returns values when I do Echo. Any thoughts?

image

@Nillth
Copy link
Collaborator

Nillth commented Sep 14, 2022

The Get-QlikUser command on line 27 is returning more than one user object.
So when you pass the $QSuser on line 34 it is failing as it will only accept a single Id not an array.

You could do the following to parse each user in the array, or modify the Get-QlikUser command to filter on the userdirectory as well

Foreach($user in $QSuser){
Update-QlikUser -id $user.id -.....
}

image

Edit: Autocorrect on mobile

@ahaydon
Copy link
Owner

ahaydon commented Sep 14, 2022

If you just want to update a single user then you should extend the filter to include the userDirectory so that only one user is returned. You can use a filter like this "userId eq '$($CSVUser.UserId)' and userDirectory eq '$($CSVUser.UserDirectory)'" assuming the userDirectory is in the CSV file.

Alternatively, if you want to update all the matching users then you can use pipelining, in this case you would change the update command to $QSUser | Update-QlikUser -customProperties $customProperties, the IDs from the QSUser variable will be passed to the -id parameter of the Update-QlikUser command one by one, and each user will be updated with the provided custom properties.

@izak004
Copy link

izak004 commented Sep 14, 2022

Thank you so much @Nillth and @ahaydon ... the code is now working :) so far.....

@izak004
Copy link

izak004 commented Sep 14, 2022

@Nillth and @ahaydon

The code is working, but it seem it can assign only one customproperty to a user. It is able to read all the users, and assigning the last customproperty from the csv file. For example, if the csv file includes

Userid, Customproperty
1234, ApplicationsAccess=License Monitor
1234, ApplicationsAccess=Operations Monitor

Only the CustomProperty of 'Operations Monitor' is assigned to the user 1234, and not both.

Here is the updated code after adding your inputs. Appreciate any input to add multiple custom properties to users.

$CSVUsers = Get-Content .\Documents\QS_User_App_Access.csv|ConvertFrom-Csv
Connect-Qlik -TrustAllCerts

#region update Missing Custom Property Values
##Update the Custom Property if a value is missing.
$UCP = $CSVUsers.Customproperty|Select -Unique
$UCPNames = $UCP|%{$($_ -split "=")[0]}|select -Unique
foreach($UCPName in $UCPNames){
    $Changes = $false
    $Values = $UCP|?{$_.StartsWith("$($UCPName)=")}|%{$($_ -split "=")[1]}
    $QSCustomProperty = Get-QlikCustomProperty -filter "Name eq '$($UCPName)'" -full
    $Values|%{
        if (!($_ -in $QSCustomProperty.choiceValues)){
            $QSCustomProperty.choiceValues += $_
            $Changes=$true
        }
    }
    if ($Changes -eq $true){
        $QSCustomProperty = Update-QlikCustomProperty -id $QSCustomProperty.id -choiceValues $QSCustomProperty.choiceValues
    }
}
#endregion update Missing Custom Property Values

#region update User object
foreach ($CSVUser in $CSVUsers){

    $QSUser = Get-QlikUser -filter "UserID eq '$($CSVUser.UserId)'" -full
    if ($null -eq $QSUser){Write-Warning "User with ID $($CSVUser.UserId) Doest Not Exist"}else{
    [string[]]$customProperties = ""
    <# #Include the next line to maintain existing properties, exclude it to only include value from CSV.
    [string[]]$customProperties = $($QSUser.customProperties|%{"$($_.definition.Name)=$($_.value)"})
    #>
    $customProperties += $CSVUser.Customproperty
    $QSUser | Update-QlikUser -customProperties $customProperties
    }
}
#endregion update User object

@izak004
Copy link

izak004 commented Sep 21, 2022

Hi @Nillth or @ahaydon

I was able to get custom property assigned to users using the above code, but the custom property seem to be getting assigned multiple times. i think so. do you know what these values mean ?

image

@ahaydon
Copy link
Owner

ahaydon commented Sep 22, 2022

You need to filter the list of properties that you assign to each user to only include those that are not already assigned, otherwise you will be appending the same property and value multiple times. Since all the new and existing properties are being combined into a list of strings in the format "key=value", you could just filter this list to unique values using Select-Object.

@izak004
Copy link

izak004 commented Sep 22, 2022

Thanks for your response @ahaydon
so I added Select-Object and it still seem to be assigning the same property multiple times when I rerun the code.

Is this the correct place to add the filter?

$UCP = $CSVUsers.Customproperty|Select-Object -Unique
$UCPNames = $UCP|%{$($_ -split "=")[0]}|select-Object -Unique
foreach($UCPName in $UCPNames){
$Changes = $false
$Values = $UCP|?{$.StartsWith("$($UCPName)=")}|%{$($ -split "=")[1]}
$QSCustomProperty = Get-QlikCustomProperty -filter "Name eq '$($UCPName)'" -full
$Values|%{
if (!($_ -in $QSCustomProperty.choiceValues)){
$QSCustomProperty.choiceValues += $_
$Changes=$true
}
}

@izak004
Copy link

izak004 commented Oct 4, 2022

Thanks for your response @ahaydon so I added Select-Object and it still seem to be assigning the same property multiple times when I rerun the code.

Is this the correct place to add the filter?

$UCP = $CSVUsers.Customproperty|Select-Object -Unique UCPNames=($_ -split "=")[0]}|select-Object -Unique foreach($UCPName in $UCPNames){ $Changes = $false Values=.StartsWith("$($UCPName)=")}|%{$($ -split "=")[1]} QSCustomProperty=Get−QlikCustomProperty−filter"Nameeq′($UCPName)'" -full $Values|%{ if (!($_ -in $QSCustomProperty.choiceValues)){ $QSCustomProperty.choiceValues += $_ $Changes=$true } }

@ahaydon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants