Posts

Showing posts with the label Powershell command

Add User To The Local Administrators Group On Multiple Computers Using PowerShell

  To achieve the objective I’m using the Invoke-Command PowerShell cmdlet which allows us to run PowerShell commands to local or remote computers. In the example below, I’ll add my User ABC to the local Administrators group on two Server (serv1, serv2) Invoke-Command -ComputerName Serv1, Serv2 -ScriptBlock {add-LocalGroupMember -Group "Remote Desktop Users" -Member ABC }   There is another everyone's favorite way here along with input file and result comment: $Computerlist = get-content "C:\temp\servers.txt" foreach ($computername in $computerlist) { Invoke-Command -ComputerName $computername -ScriptBlock {add-LocalGroupMember -Group "Administrators" -Member GIN } Write-host "ABC User added in $computername" }    

How to Get LUN WWN ID on Windows Server 2012 Operating System

Go to powershell and run below mentioned command. Get-Disk -Number 17 | Select UniqueId   Replace numeric digit with actual disk ID (can fetch that from disk management console) output : UniqueId -------- 60002AC0000000000000006A003430FA

Find AD Users who never logged on using Powershell

We can use the Active Directory powershell cmdlet   Get-ADUser   to query users from AD. We can find and get a list of AD users who never logged in at least one time by checking the AD attribute value   lastlogontimestamp .   The below command lists all users who never logged on. Get-ADUser -Filter {(lastlogontimestamp -notlike "*")} | Select Name,DistinguishedName If you want to list only enabled ad users, you can add one more check in the above filter.   Get-ADUser -Filter {(lastlogontimestamp -notlike "*") -and (enabled -eq $true)} | Select Name,DistinguishedName If you are familiar with LDAP filter you can also find never logged in users by using ldap filter.   Get-ADUser -ldapfilter '(&(!lastlogontimestamp=*)(!useraccountcontrol:1.2.840.113556.1.4.803:=2))' | Select Name,DistinguishedName In most cases, we may want to find AD users who created in last certain days or months and not logged in their system. To achieve this, we need to fi...