V
V
Vasily Sheshunov2020-10-19 22:22:05
PowerShell
Vasily Sheshunov, 2020-10-19 22:22:05

Getting data with powershell from AD?

I want to write a small program to get data from the active directory about the last user authorization on the network, under my account. Accordingly, there is a field (TextBox) for entering a login, a field in which the date and time of the last login (FormLabel) and a search button (Button) will be indicated. Below code for button : $FormButton.Add_Click(
{$FormLabel.Text = [datetime]::FromFileTime((Get-ADUser -identity $FormLabel.selectedItem -Properties LastLogonDate ).LastLogonDate ).ToString('dd mm yy : hh ss ')})
I run it, enter the login, press the button and an error appears that the TextBox field is null.
Tell me where I went wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxKozlov, 2020-10-20
@MaxKozlov

FormLabel.selectedItem is "a field (TextBox) for input of login"? Vryatli ;-)
btw, LastLogonDate is not the best choice, it is replicable, of course, but sometimes there is a delay of several days.
lastlogon is more correct, but you need to poll all DCs, since it is not replicated

S
strangerror, 2020-10-22
@strangerror

Are you sure you are using a TextBox? It is not visible in the code above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question