Use Get-ADUser to get locked status and if locke give a choice to unlock it.

Hi guys and girls,
Im startling to learn powershell scripting and have made my first tool/Script.
Below script is the one i use, however i do have an problem i would like some help with.
I use the script to display some basic info and also to show if the user is lockedout or not.
However i do would like to have the choice to unlock the user in the script as well, therefore im using the if statement.
But dont get it to return the value i want. What i want it to do is to check if the account is locked if so ask if it should unlock it. Any help or input is appreciated.
/Json
$userinput = Read-Host "Enter Username Here"
Get-ADUser -Identity $userinput -Properties * | Select-Object DisplayName, city, department, EmailAddress, HomeDirectory, MobilePhone, OfficePhone, Manager, PasswordExpired, PasswordLastSet, LockedOut
  If(((Get-ADUser -Identity $userinput -Properties lockedout).lockedout = $true))

Hi there, I've not tested this properly but it should do the trick.
add-type -AssemblyName System.DirectoryServices.AccountManagement
$userinput = Read-Host "Enter Username Here"
$res = Get-ADUser -Identity $userinput -Properties DisplayName, city, department, EmailAddress, HomeDirectory, MobilePhone, OfficePhone, Manager, PasswordExpired, PasswordLastSet, LockedOut | Select-Object DisplayName, city, department, EmailAddress, HomeDirectory,
MobilePhone, OfficePhone, Manager, PasswordExpired, PasswordLastSet, LockedOut
if ($res.lockedout -eq $true){
$unlock = Read-host "Unlock? Y/N"
if ($unlock -eq "Y")
$context = [System.DirectoryServices.AccountManagement.ContextType]::Domain
[System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context,$userinput).UnlockAccount()

Similar Messages

  • Why is it that when I am trying to install an adobe product, I get 33% of the way through and then it gives me an error "unable to load metafile"??  It happened with Reader and now with Flashplayer.  With the Reader, I was able to find a different install

    Why is it that when I am trying to install an adobe product, I get 33% of the way through and then it gives me an error "unable to load metafile"??  It happened with Reader and now with Flash player.  With the Reader, I was able to find a different installation link using the troubleshooting guide.  I cannot find the same with flash player.  Please tell me how to install Flash player because there is a website that I cannot even view without it.  BTW That is annoying that I cannot even see the website without flash player
    my system is XP

    Use these installers:
    Flash Player for ActiveX (Internet Explorer)
    Flash Player Plug-in (All other browsers)
    Flash Player for Mac OS X
    For Adobe Reader go to http://get.adobe.com/reader/enterprise/

  • Different _scope parameter of Enqueue_ lock object and Dequeue_ lock objec

    Hi, all.
    When we create lock object and generate enqueue_<lock object> and
    dequeue_<lock object>, the default value of _scope is
    enqueue : _scope = 2(update owner only)
    dequeue : _scope = 3(for both dialog owner and update owner).
    Does anyone tell me the reason of this different default values?
    i read help.sap.com - lock related help but i couldn't get the idea
    of these different default values between enqueue and dequeue.
    Best Regards.
    Sejoon

    Hi,
    When you use ENQUEUE, the owner is going to lock that record. So at that time, the only person who can modify the record in the one who has locked it using ENQUEUE. So only he needs to be informed.
    Whereas when you use DEQUEUE, the owner who has locked the record and processed it + the 2nd user who wants to lock it needs to be informed. Hence it is to update the 1st User(who has done the update and planning to release the lock) + 2nd User(who wants to do the update and planning to lock the record ).
    Best regards,
    Prashant

  • I recently thought I was updating my Safari browser. When completed, I put all those little files that were on the desktop into the trash. Now my trash is saying it can't be emptied because there are locked files and I don't know how to unlock them

    I recently thought I was updating my Safari browser. When completed, I put all those little files that were on the desktop into the trash. Now my trash is saying it can't be emptied because there are locked files and I don't know how to unlock them or get them out of my trash and they keep multiplying. And to make matters worse, I tried renaming them as pdf files thinking that might do the trick.

    oh boy ! I'd ask you if you knew what kind of files they were or where they came from, but I don't think you could help me a bunch. Try going to the Utilities folder and running Disk Utilities.  If you want to empty the Trash and it won't empty, go to the finder and choose "secure Empty trash". Worse case scenario-you may have to reinstall Snow Leopard, but I don't know what else to suggest. If you have a DVD of Snow Leopard, boot up from that,  and reinstall the OS. This will not touch the stuff you have on your Hard Drive, then you can update from 10.6 to 10.6.8, otherwise Onyx? Maybe those files are part of the OS which needs them to keep running.  if you hold down the Shift key on reboot, you can reboot in Safe mode and maybe you can take the files out of the trash that way
    good luck
    John B

  • I am the administrator on my computer but my new hard drive is locked and does not give me permission to unlock

    I am the administrator on my computer but my new hard drive is locked and does not give me permission to unlock. How do I fix this? I already tried fixing permissions.

    Whoops! I don't know why but this time when I clicked on the lock it opened and I was able to fix the problem. I am curious tho' as to why this happened.

  • How do I use Get-ADUser to get just the Managers attribute? And then get rid of duplicates in my array/hash table?

    Hello,
          I am trying to just get the Managers of my users in Active Directory. I have gotten it down to the user and their manager, but I don't need the user. Here is my code so far:
    Get-ADUser-filter*-searchbase"OU=REDACTED,
    OU=Enterprise Users, DC=REDACTED, DC=REDACTED"-PropertiesManager|SelectName,@{N='Manager';E={(Get-ADUser$_.Manager).Name}}
    |export-csvc:\managers.csv-append 
    Also, I need to get rid of the duplicate values in my hash table. I tried playing around with -sort unique, but couldn't find a place it would work. Any help would be awesome.
    Thanks,
    Matt

    I would caution that, although it is not likely, managers can also be contact, group, or computer objects. If this is possible in your situation, use Get-ADObject in place of Get-ADUser inside the curly braces.
    Also, if you only want users that have a manager assigned, you can use -LDAPFilter "(manager=*)" in the first Get-ADUser.
    Finally, if you want all users that have been assigned the manager for at least one user, you can use:
    Get-ADUser
    -LDAPFilter "(directReports=*)" |
    Select @{N='Manager';E={ (Get-ADUser
    $_.sAMAccountName).Name }}
    -Unique | Sort Manager |
    Export-Csv .\managerList.csv -NoTypeInformation
    This works because when you assign the manager attribute of a user, this assigns the user to the directReports attribute of the manager. The directReports atttribute is multi-valued (an array in essence).
    Again, if managers can be groups or some other class of object (not likely), then use Get-ADObect throughout and identify by distinguishedName instead of sAMAccountName (since contacts don't have sAMAccountName).
    Richard Mueller - MVP Directory Services

  • Method of fetching Account status and user locked date in Portal.

    Hi,
    Can anyone suggest me the method name  in UME API in Sap Ep for fetching User Account Status and Last User Locked Date. Or suggest a related code for it.
    user database is LDAP.
    Thanks

    Hi Abhai,
    The class (actually Interface) you're looking for is IUserAccount. You can get this from the IUser by using the method getUserAccounts().
    The IUserAccount provides all sort of methods like lockDate(), isLocked(), getLockReason().
    See more in https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/library/ep/_d-f/ep%206.0%20sp2%20usermanagement%20public%20api
    Best regards,
    Amit

  • Syntax for Get-ADUser to get only these items "DistinguishedName" "SamAccountName" "Title"

    Is there a way to pull these three parts in PowerShell???

     you always get the default set of properties, whether you ask for them or not. [...] always get all the default properties.
    Richard Mueller - MVP Directory Services
    It is true that the default set of properties is retrieved, but with a few more lines the OP can get what he is looking for. I had the same problem and overcame it by defining the output I wanted to display.  The following code did what I think he is
    asking for my test user; though my test user had no title.  
    $reportObject = @()
    $userList = Get-ADUser USERNAME -Properties DistinguishedName,SamAccountName,Title
    $userList | %{
    $output = "" | Select DistinguishedName,SamAccountName,Title
    $output.sAMAccountName = $_.sAMAccountName
    $output.DistinguishedName = $_.DistinguishedName
    $output.Title = $_.Title
    $reportObject += $output
    $output | fl *
    $reportObject | Convertto-CSV -NoTypeInformation | Out-File C:\Output.txt
    you can pull any -property that is a "Attr LDAP Name" (List: http://www.kouti.com/tables/userattributes.htm)
    you may also find the -filter flag useful if you have to get more than one user.

  • Status and Tracking: Lock Function overide due to status change?

    Hello experts,
    Does anybody know whether it is standard functionality that a user with only R_STS_PT authorisation can unlock his/her planning by changing the status to "in process"?
    Should it not be the case that I higher hierarchy node or someone with R_STS_SUP authorisation must first unlock the plannig before for somone with only R_STS_PT authorasation can perform any status change? I am currently unsure whether what we are observing is a feature or a bug which we had previously not noticed.
    Thanks in advance,
    Will

    Hi William,
    Persons responsible for executing the planning process i.e. the User (Auth: R_STS_PT) are assigned to an area of responsibility (hierarchy node) within a subplan. They are either assigned to their own area of responsibility directly or are assigned as a substitute. The person responsible uses the STS, firstly to jump to his or her planning application, secondly to set the status of his or her own planning, and thirdly to monitor and set the status of any people who may be assigned under them.
    For example, the person responsible for node 11 of the subplan u201Ccost center planningu201C  logs on to planning session 1 in the STS. In this way he or she can obtain the detailed view for his or her cost center.
    Auth: R_STS_SUP is for Planning Coordinators for monitoring the entire planning process and thus have special access rights. So R_STS_PT & R_STS_SUP are the same, except that you are only allowed to set certain statuses of a task on the basis of the hierarchy levelto which you are assigned (this means, whether you are executing (R_STS_PT) or supervising a particular planning task (R_STS_SUP))
    Manoj

  • I have done a hard reset on my Airport Express and re-set it up.  When it is to restart, all I get is the slow amber light and the utility gives an error message.

    I've tried this several times with the same results.
    I press and hold the reset button until a fast blinking amber light.  AirPort Utilities picks it up and identifies it as AirPort Express 802.11n.
    I then "Replace the previously selected profile with default settings" and indicate that I want the AirPort Exp. to join my current network and input the information.
    At the last step, Utility says an error has occurred and that it can't find the AirPort.
    Any help would be appreciated.

    Assuming it is not simply broken, a slowly flashing LED probably means the TC is not receiving an IP address from the modem. Make sure you power down your modem whenever you change what is connected to it.
    Having to unplug the Ethernet cable from the TC and plugging it in to your Mac repeatedly so that you can communicate is tedious enough, but endeavor to add the power cycle exercise to that action.

  • Replaced keyboard and now the caps lock light and num lock light are blinking and no screen???

    I just replaced my keyboard on my HP DV6-2155DX Laptop and got it all back together and now there is no display on the screen and the caps lock light that indicated that caps lock is on and the num lock indicator light are both flashing. any help and all??? thanks you

    Ouch, doesn't sound good, but...
    Have you done a PRAM reset, CMD+Option+p+r...
    http://support.apple.com/kb/HT1379
    In fact, do 3 in a row, takes a bit of time.
    Intel-based Macs: Resetting the System Management Controller (SMC)...
    http://support.apple.com/kb/HT3964

  • HT1212 how do i unlock or re-enable ipod touchwhen it says ipod isdisabled and does not giv the option to unlock

    itunes will not recognize it o sync it and the screen says ipod is disabled and doesnt allow you to unlock it

    Read the second part of the article:
    If you have never synced your device with iTunes, or you do not have access to a computer
    If you see one of following alerts, you need to erase the device:
    "iTunes could not connect to the [device] because it is locked with a passcode. You must enter your passcode on the [device] before it can be used with iTunes."
    "You haven't chosen to have [device] trust this computer"
    If you have Find My iPhone enabled, you can use Remote Wipe to erase the contents of your device. If you have been using iCloud to back up, you may be able to restore the most recent backup to reset the passcode after the device has been erased.
    Alternatively, place the device in recovery mode and restore it to erase the device:
    Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
    Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to shut down.
    While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
    Continue holding the Home button until you see the Connect to iTunes screen.
    iTunes will alert you that it has detected a device in recovery mode. Click OK, and then restore the device.

  • FILES: how do I get rid of EXEC status and set them to open with "none"?

    I dropped my laptop and damaged the drive. My computer forensic friend salvaged specific files.
    Transfered to a FAT32 drive and then copied to Mac.
    Most of files are fine with the exception of some setings files that showed up as Unix executables. The few original files that I have to compare them to, show "Document" as the file "Kind" and the "open with" shows "none" in Get Info
    When I look at the contents of the files they look fine. How do I get rid of the EXEC status and set them to open with "none"?
    Any help would be greatly appreciated.
    These are settings files for a set of .wav samples for an AU drum plug-in.

    If you have xcode installed, you might want to find out what the type and creator code for these files should be. Since the files have visited a FAT32 file sytem, you will have lost all resource forks as well as type and creator HFS+ meta data.
    So assuming you do have xcode, create a new AU drum plug-in file then in the terminal:
    <pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #444; background: #eee; line-height: normal">/Developer/Tools/GetFileInfo newfile</pre>
    Then use:
    <pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #444; background: #eee; line-height: normal">/Developer/Tools/SetFile -t '(insert type)' -c '(insert creator)' oldfile</pre>
    If there's a lot of these you might automate the process using the find command.
    Cole

  • How do I run Get-ADUser and filter out two separate OUs

    Ha! I was assuming that Where-Object wouldn't do me any better. Well, I guess I made an ass out of me. ;)
    Your first script is what I will use. We have some user accounts in other OUs that are disabled for other reasons.
    It's little quirks like this that keep me from using Powershell more often.
    Thanks Matt!

    Hi again all!I am trying to write a script that will search for AD users that have the "Password Never Expires" box checked, but not if they are in one of two OUs. These OUs are not parent/child, they are separate.If I run this, I get about 30 results:
    Powershellget-aduser -filter { PasswordNeverExpires -eq $true }Some of the results are in the "Disabled Accounts" OU, some are in the "Contractors" OU, and the rest are in neither.
    If I run either of these, I get zero results:
    Powershellget-aduser -filter { PasswordNeverExpires -eq $true -and DistinguishedName -notlike "*Disabled*"}get-aduser -filter { PasswordNeverExpires -eq $true -and ( DistinguishedName -notlike "*Disabled*" -and DistinguishedName -notlike "*Contractors*")}I know for a fact that I have users that are not in either of these two OUs that have that box checked because I...
    This topic first appeared in the Spiceworks Community

  • Set PF-STATUS and use SY-UCOMM in an Exit FM

    Hi,
    I am working on an Exit function, and I am trying to read the screen status and then the user's actions, so that I could code for the SY-UCOMM. For some reason, my program is not working. Is it possible to add the PF-STATUS and SY-UCOMM to the Exit function to process the user's actions? Please advise.
    Thanks,
    RT

    Hi Ravikumar,
    I was able to use the parameters in the Exit provided in the Exit FM to process the necessary data. I have other requirements where I would have to code in the Exit FM to detect the user's actions and process them within the Exit to manipulate the tables. I added some code specified in the previous post, but it doesn't seem to get the OK_CODE; therefore, no processing of the data was happening when I tested by clicking on the yellow arrow to exit. I am able to determine the OK_CODE though.
    Would you have any sample code suggestions when using the Exit for SET PF-STATUS and SY-UCOMM?
    Thanks so much.
    RT

Maybe you are looking for

  • Colors not consistent with Snow Leopard 10.6 on an Eizo SX2761W monitor

    I am unable to get any color consistency with Snow Leopard 10.6 on my Eizo SX2761W display. Most of the actual "content" (i.e. images, videos, websites, etc.) is displayed very saturated and dark, much more saturated and dark than in 10.5.8. I presum

  • IWeb not finding my MobileMe Galleries

    I've just found the MobileMe Gallery widget and wanted to play around with it to see what exactly it does and what it looks like. I've made a new blank page to try it out and dragged the widget onto the page, but the little floating box says "(No alb

  • Itunes won't open, even after reintallation

    itunes just quit working.  I uninstalled, shut down the PC, then reinstalled.  It all looks good during installation...the wizard works fine, but when you try to launch you get nothing.  It won't open from the shortcut on the desktop, or the program

  • Legal Entity and Operating Unit Setup

    Hi, we are in a process of implementing Oracle Financials R12.1.3 to a group of company (Ex:"A"). That parent company ("A") associates with another three subsidiaries (Ex: A1, A2 and A3). All these four companies can share the same ledger and operati

  • Castor XSD Code Generation ANT task: mapping  XML file?

    Hello, I am new to Castor and am using the Castor Code Generator ANT task to generate code from a XSD schema file. I am using a binding XML file as well. One thing that I have a question about is the needed XML mapping file. I set the '*generateMappi