Skip to content
New issue

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

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

Already on GitHub? # to your account

Function Get-ObservationWindow get troubles on -verbose #43

Open
sPROFFEs opened this issue Mar 2, 2024 · 0 comments
Open

Function Get-ObservationWindow get troubles on -verbose #43

sPROFFEs opened this issue Mar 2, 2024 · 0 comments

Comments

@sPROFFEs
Copy link

sPROFFEs commented Mar 2, 2024

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}

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

No branches or pull requests

1 participant