{"id":5439,"date":"2015-12-19T19:24:41","date_gmt":"2015-12-19T11:24:41","guid":{"rendered":"http:\/\/rmohan.com\/?p=5439"},"modified":"2015-12-19T19:24:41","modified_gmt":"2015-12-19T11:24:41","slug":"powershell-commands","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5439","title":{"rendered":"powershell commands"},"content":{"rendered":"<p>PowerShell is the command line included with Windows.<br \/>\nIt is a very handy tool for doing simple tasks without the GUI. In this guide,<br \/>\nGetting a Process<br \/>\nRather than using the Task Manager or a similar tool, you can use PowerShell to retrieve information about a specific process and kill it,<br \/>\nif needed. This will show the process ID (Id ProcessName):<\/p>\n<p>Get-Process ProcessName<br \/>\nOfficial documentation<\/p>\n<p>Killing a Process<br \/>\nOnce you have the process ID of a process, you can kill it:<\/p>\n<p>Stop-Process -id PID<br \/>\nOfficial documentation<\/p>\n<p>Getting Contents of a File<br \/>\nYou can actually get the content of a file (for example a .txt file) and view it in PowerShell:<\/p>\n<p>Get-Content file.txt<br \/>\nOfficial documentation<\/p>\n<p>Getting Item Information<br \/>\nYou can get information about a certain file with the Get-Item command. The cool thing about this is that you can use it to return multiple kinds of data, for example, you can see the last time somebody accessed a file:<\/p>\n<p>$(Get-Item D:\\Users\\mohan\\Desktop\\file.txt).lastaccesstime<br \/>\nOfficial documentation<\/p>\n<p>Adding a New Active Directory User<br \/>\nYou can add an Active Directory user with the New-ADUser command:<\/p>\n<p>New-ADUser -SamAccountName &#8220;mohan&#8221; -GivenName &#8220;mohan&#8221; -Surname &#8220;Edwards&#8221; -DisplayName &#8220;mohan David Edwards&#8221;<br \/>\nOfficial documentation<\/p>\n<p>Removing an Active Directory User<br \/>\nRemoving an Active Directory user with PowerShell is possible too:<\/p>\n<p>Remove-ADUser mohan<br \/>\nYou can use a DN, SAM account name, SID, or an object GUID here.<\/p>\n<p>Official documentation<\/p>\n<p>Adding an Active Directory group<br \/>\nYou can add an Active Directory group with PowerShell very easily:<\/p>\n<p>New-ADGroup \u2013name Staff\u201d \u2013groupscope Global<br \/>\nUse the name of the new Active Directory group for -name and change the group scope if needed.<\/p>\n<p>Official documentation<\/p>\n<p>Removing an Active Directory group<br \/>\nLikewise, you can also remove an Active Directory group with PowerShell:<\/p>\n<p>Remove-ADGroup Staff<br \/>\nOfficial documentation<\/p>\n<p>Finding All Domain Controllers<br \/>\nYou can find all domain controllers in a domain with PowerShell by finding out which computers are in the Domain Controllers group:<\/p>\n<p>Get-ADGroupMember &#8216;Domain Controllers&#8217;<br \/>\nDisabling an Active Directory account<br \/>\nYou can disable an account in Active Directory to prevent a user from logging in. This can be done from PowerShell to avoid having to use the GUI for this simple task:<\/p>\n<p>Disable-ADAccount mohan<br \/>\nAgain, you can use a DN, SAM account name, SID, or an object GUID here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell is the command line included with Windows. It is a very handy tool for doing simple tasks without the GUI. In this guide, Getting a Process Rather than using the Task Manager or a similar tool, you can use PowerShell to retrieve information about a specific process and kill it, if needed. This will [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5439"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5439"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5439\/revisions"}],"predecessor-version":[{"id":5440,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5439\/revisions\/5440"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}