Open ShalakaKshirsagar opened 2 years ago
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.
Hi @ahaydon
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
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
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.
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)'
$inactive = Get-Date $inactive = $inactive.AddDays(-$InactivityThreshold)
$inactive =Get-Date $inactive -Format 'yyyy-MM-ddTHH:mm:ss'
Connect-Qlik | Out-Null
$a=Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full
foreach ($b in $a){ $c = $b.user.userId Write-Host $c }
anythign missing here?
Hello @ahaydon
I am getting LastUsed value something like - "lastUsed":"2022-03-26T15:15:06.468Z"
Do i need to convert this format ?
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
}
I would simplify your test further, what is returned when you just run Get-QlikProfessionalAccessType -filter "lastUsed lt '$inactive'" -full
?
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
on + FullyQualifiedErrorId : InputObjectNotBound,Remove-QlikProfessionalAcces sType