{"id":5459,"date":"2020-05-18T17:00:00","date_gmt":"2020-05-18T15:00:00","guid":{"rendered":"https:\/\/www.razumny.no\/?p=5459"},"modified":"2020-04-25T23:14:17","modified_gmt":"2020-04-25T21:14:17","slug":"powershell-check-computer-last-logon-date","status":"publish","type":"post","link":"https:\/\/www.razumny.no\/?p=5459","title":{"rendered":"PowerShell: Check computer last logon date"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In a recently closed ticket, I had specified that the solution would be automatically applied upon reboot of a computer. As so often happens one of the twenty or so users affected by the solution emailed to say that it didn&#8217;t work. Having dealt with said user before, I had a hunch that they hadn&#8217;t actually read the solution text, and wanted to see if I could find out when the computer had last been rebooted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Predictably (particularly assuming you&#8217;ve read the title of this post), PowerShell has an applet for that. This time, we&#8217;re looking at the <code>Get-ADComputer<\/code> applet. By specifying the computer object using the <code>Identity<\/code> parameter, and getting all properties using the <code>Properties<\/code> parameter, we get a dump of all the properties for the AD computer object, much the same as we did when <a href=\"https:\/\/www.razumny.no\/?p=5446\">retrieving properties for a user object<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The complete query looks like this: <code>Get-ADComputer -Identity %COMPUTER% -Properties *<\/code>. By looking through the output for the <code>LastLogonDate<\/code>, we can quickly identify when a user last logged on to the computer. Other useful properties are  <code>AccountExpirationDate<\/code>,  <code>Created<\/code>, telling us when the computer object was added to AD, and <code>Enabled<\/code>, which &#8211; if set to False &#8211; tells us that login is impossible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I recommend running the command against a machine and poking around to see if you can find other properties that are useful to you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a recently closed ticket, I had specified that the solution would be automatically applied upon reboot of a computer. As so often happens one of the twenty or so users affected by the solution emailed to say that it didn&#8217;t work. Having dealt with said user before, I had a hunch that they hadn&#8217;t [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[820],"tags":[1245,1246,969,1242],"class_list":["post-5459","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-get-adcomputer","tag-identity","tag-powershell","tag-properties"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p2ukSU-1q3","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":5446,"url":"https:\/\/www.razumny.no\/?p=5446","url_meta":{"origin":5459,"position":0},"title":"Powershell: Retrieving all properties for a given user object","author":"Aleksander Nordgarden-R\u00f8dner","date":"20\/04\/2020","format":false,"excerpt":"I was asked to provide an overview of all available properties in an Active Directory user object for an upcoming project. As it turns out, that is very easily accomplished. Unsurprisingly, PowerShell has an applet for this. We use the Get-ADUser applet, with the parameters Identity to identify the user\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"Output of get-aduser command, filtering on identity and specific proeprties","src":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5451,"url":"https:\/\/www.razumny.no\/?p=5451","url_meta":{"origin":5459,"position":1},"title":"PowerShell: Pipe output to CSV file","author":"Aleksander Nordgarden-R\u00f8dner","date":"11\/05\/2020","format":false,"excerpt":"Last week, I showed you how to get specific properties for all users in a given OU. Knowing that the output of that query quickly gets hard to navigate, wanting to remove the extraneous data that the customer didn't request, and assuming that they wanted to manipulate the data, I\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5450,"url":"https:\/\/www.razumny.no\/?p=5450","url_meta":{"origin":5459,"position":2},"title":"PowerShell: Getting properties for all user objects in a given OU","author":"Aleksander Nordgarden-R\u00f8dner","date":"04\/05\/2020","format":false,"excerpt":"Two weeks ago, I showed you how I got some specific properties for a specific user. Perhaps unsurprisingly, the next request from my customer was a similar dump from a specific OU. While the Identity parameter works well when you're dealing with a specific user, it doesn't help when you\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4297,"url":"https:\/\/www.razumny.no\/?p=4297","url_meta":{"origin":5459,"position":3},"title":"Powershell: Exporting Active Directory Contacts","author":"Aleksander Nordgarden-R\u00f8dner","date":"16\/10\/2017","format":false,"excerpt":"Some time ago, I needed to have a list of all Contacts registered in Active Directory. Knowing that there are a lot of them (numbering at least eighty), getting the data manually was not a viable alternative, particularly knowing that the same objective can be achieved through Powershell. I eventually\u2026","rel":"","context":"In &quot;code examples&quot;","block_context":{"text":"code examples","link":"https:\/\/www.razumny.no\/?cat=119"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5392,"url":"https:\/\/www.razumny.no\/?p=5392","url_meta":{"origin":5459,"position":4},"title":"PowerShell: Look up all direct reports","author":"Aleksander Nordgarden-R\u00f8dner","date":"06\/04\/2020","format":false,"excerpt":"In the Organisation tab of a user object in Active Directory, you have the option to set who is the manager of a given user. While this may seem unnecessary, I have found it very useful when supporting a customer where I don't know the reporting lines, as it gives\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7213,"url":"https:\/\/www.razumny.no\/?p=7213","url_meta":{"origin":5459,"position":5},"title":"Verify what RSAT features are installed","author":"Aleksander Nordgarden-R\u00f8dner","date":"07\/08\/2023","format":false,"excerpt":"Before summer, I showed you how to install ADUC using PowerShell. ADUC, however, is not the only tool in the RSAT toolbox. Here, then, is how you can get an overview of all of them, as well as whether or not they are installed on the computer: Start PowerShell with\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5459"}],"version-history":[{"count":1,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5459\/revisions"}],"predecessor-version":[{"id":5460,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5459\/revisions\/5460"}],"wp:attachment":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}