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

Issue in executing below code - # Remove Professional Access passes over date threshold #180

Open
ShalakaKshirsagar opened this issue Apr 8, 2022 · 7 comments

Comments

@ShalakaKshirsagar
Copy link

Hi @ahaydon ,

I am trying to remove the Professional Access passes over date threshold date. However not working and getting below error.

Code

Set the inactivity threshold. This is interactive. A non-interactive version can use this approach:

$InactivityThreshold = '30' # This is for 30 days

$InactivityThreshold = Read-Host -Prompt 'Input the username date threshold for inactivity (e.g. 90)'

Get date format for 90 days ago

$date = Get-Date
$date = $date.AddDays(-$InactivityThreshold)
$date = $date.ToString("yyyy/MM/dd")
$time = Get-Date
$time = $time.GetDateTimeFormats()[109]
$inactive = $date + ' ' + $time

Connect using Qlik-CLI

Connect-Qlik | Out-Null

Write-Host $inactive

Remove Professional Access passes over date threshold

Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full | Remove-QlikProfessionalAccessType

=============================================================================

Error

Remove-QlikProfessionalAccessType : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that
take pipeline input. At line:21 char:76

  • Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full |
    Remov ...+
    • CategoryInfo : InvalidArgument: ([{"id":"acdefff...alAccessType
      "}]:PSObject) [Remove-QlikProfessionalAccessType], ParameterBindingExcepti
      on + FullyQualifiedErrorId : InputObjectNotBound,Remove-QlikProfessionalAcces
      sType
@ahaydon
Copy link
Owner

ahaydon commented Apr 11, 2022

It looks like the issue is with the command $time.GetDateTimeFormats()[109], when I run this it returns nothing and so the date being used in the filter is '2022/03/12 '. Without the space at the end it would work as it assumes midnight, but the space is causing it to fail.

If I run $time.GetDateTimeFormats().Count I get a result of 30, so there is no 109th item in the list to select.

@ShalakaKshirsagar
Copy link
Author

Hi @ahaydon

many thanks for the response.

$date = Get-Date
$date = $date.AddDays(-$InactivityThreshold)
$date = $date.ToString("yyyy-MM-dd")
$time = Get-Date
$time = $time.GetDateTimeFormats()[109]
$inactive = $date + ' ' + $time

Variable "$inactive" contains "2022-04-01 09:38" e.g. I entered 10 as the input and I am getting "2022-04-01 09:38" value which is being passed to the forloop

I am actually referring to below script by Levi Turner

https://github.com/levi-turner/QlikSenseScripts/blob/master/qs-cli/qs-cli-remove_professional_analyzer_licenses.ps1

Request you to guide me which date format is needed to be passed "Remove-QlikProfessionalAccessType" for below comment.

Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full | Remove-QlikProfessionalAccessType

@ahaydon
Copy link
Owner

ahaydon commented Apr 11, 2022

It looks like this depends on the version of PowerShell being used, since that works for you I assume you are using PowerShell 5. The correct format should look like this '2022-04-11T10:58:54', so you can use $time.GetDateTimeFormats()[87] on PowerShell 5. For PowerShell 7 it seems that it should be 21 rather than 87, but not sure how consistent it is.

A more consistent approach would be to use $time = Get-Date -Format 'yyyy-MM-ddTHH:mm:ss' as it should work on any version of PowerShell.

@ShalakaKshirsagar
Copy link
Author

Great !!

Many thanks for the quick input. I tried both the suggested options.. However still no luck ! :(

BEFORE removing, i am trying to print the UserId which will be removed (just for the testing) using foreach loop.
However its not returns any records

$InactivityThreshold = Read-Host -Prompt 'Input the username date threshold for inactivity (e.g. 90)'

Get date format for 90 days ago

$inactive = Get-Date
$inactive = $inactive.AddDays(-$InactivityThreshold)

#Write-Host $inactive

$inactive =Get-Date $inactive -Format 'yyyy-MM-ddTHH:mm:ss'

Connect using Qlik-CLI

Connect-Qlik | Out-Null

Remove Professional Access passes over date threshold

#Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full | Remove-QlikProfessionalAccessType

$a=Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full

foreach ($b in $a){
$c = $b.user.userId
Write-Host $c
}

anythign missing here?

@ShalakaKshirsagar
Copy link
Author

Hello @ahaydon

I am getting LastUsed value something like - "lastUsed":"2022-03-26T15:15:06.468Z"

Do i need to convert this format ?

@ShalakaKshirsagar
Copy link
Author

Hello @ahaydon ,

Below simple script is also not working.. seems its not executing for loop. Anything missing?

$QSUsers=Get-QlikUser -filter "inactive eq true" -full

foreach ($QSUser in $QSUsers){

#$c = $b.userId
Write-Host  $QSUsers.userId

}

@ahaydon
Copy link
Owner

ahaydon commented Apr 11, 2022

I would simplify your test further, what is returned when you just run Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full?

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

2 participants