Skip to content

Function Get-ObservationWindow get troubles on -verbose #43

@sPROFFEs

Description

@sPROFFEs

Errors when using -Verbose on lines 565/572

Powershell advices -
Error: Cannot index into a null array.
Error in method invocation because [System.String] does not contain a method named 'ConvertLargeIntegerToInt64'.

PosibleFix:
Change the function Get-ObservationWindow on lines 565/572 to

function Get-ObservationWindow($DomainEntry)
{
    # Check if $DomainEntry is null
    if ($null -eq $DomainEntry) {
        Write-Host "Error: DomainEntry is null."
        return $null
    }

    # Check if 'Properties' exists and is not null
    if ($null -eq $DomainEntry.Properties) {
        Write-Host "Error: Properties is null."
        return $null
    }

    # Check if 'lockoutObservationWindow' exists in the object's properties
    if ($DomainEntry.Properties.ContainsKey('lockoutObservationWindow')) {
        # Get the value of the 'lockoutObservationWindow' attribute
        $lockObservationWindow_attr = $DomainEntry.Properties['lockoutObservationWindow']

        # Check if the attribute has an assigned value
        if ($null -ne $lockObservationWindow_attr -and $lockObservationWindow_attr.Count -gt 0) {
            # Convert the value from LargeInteger to TimeSpan
            $observation_window = [System.TimeSpan]::FromTicks($lockObservationWindow_attr.Value)

            # Return the observation window in minutes
            return $observation_window.TotalMinutes
        } else {
            Write-Host "lockoutObservationWindow attribute has no value."
            return $null
        }
    } else {
        Write-Host "lockoutObservationWindow attribute not found."
        return $null
    }
}

I am not sure if it modifies much the behavior of the original function but it seems to work.
Feel free to modify it and comment

Also on line 265 be sure you´ve changed the parameter $Message to ${Message}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions