Sie sind auf Seite 1von 3

Some Basic Power Shell Commands Get-Children ls Get-Service Get-Service | format-list Get-Service | format-list -Property * Get-Help Get-Service Get-Command

Get-Help Get-Command Get-Help Get-Command -detailed Get-Help Get-Command -Full Using an OBJ $DNSObj=Get-Service DNS $DNSObj.Status

With Piping Get-Service | Where-Object {$_.status -eq "Running"} or

Get-Service | Where {$_.status -eq "Running"} (alias of the above cmdlet) Checking the alias of dir cmd alias dir -----> Displays Get-Children

Power Shell Method $out=[adsi](LDAP://cn=users,dc=rit,dc=com) $ab=$out.Create(user,cn=u1) $ab.put(sAMAccountname,u1) ;$ab.put(useraccountcontrol,4130) $ab.SetInfo() {4130-user acc will be enabled 4128-------------------- disabled(default)}

or $ab.PSBase.InvokeSet('AccountDisabled',$true or $false) $ab.SetInfo() To edit the properties of a user object $Objusr=[ADSI]"LDAP://CN=Naveen Krishna,OU=OU1,DC=IT,DC=NET" $Objusr.Put("SN",'Krishna') $Objusr.Put("UserPrincipalName",'naveen.krishna@it.net') $Objusr.SetInfo()

To view all the attributes supported by an obj $Objusr | Get-Member or $Objusr.PSbase.Properties TO View a particular attribite $Objusr.Get("sAMAccountName") To enable the account $out=[adsi](LDAP://cn=u1,cn=users,dc=rit,dc=com) $out.psbase.InvokeSet(accountdisabled,$false) $out.SetInfo() To set password to a account $out=[adsi](LDAP://cn=u1,cn=users,dc=rit,dc=com) $out.SetPassword(rit-123) To force the user to change the pwd at next Logon $out=[adsi](LDAP://cn=u1,cn=users,dc=rit,dc=com) $out.Put("PwdLastSet",0) $out.SetInfo() To Change the CN of an obj $ObjUsr=[ADSI]"LDAP://cn=u1,cn=users,dc=rit,dc=com $ObjUsr.PSBase.Rename("CN=<New CN>") To Move a User $ObjUsr=[adsi](LDAP://CN=u1,CN=users,DC=rit,DC=com) #Connect to the User Obj $ObjUsr.PSBase.MoveTo("LDAP://OU=Ou,dc=rit,dc=com") #Specify TargetOU DN To Delete a User Account $ObjOu=[adsi](LDAP://cn=users,dc=rit,dc=com) #Connect to the Container/OU

$ObjOu=.Delete("user","CN=u1") To creat a group $out=[adsi](LDAP://cn=users,dc=rit,dc=com) $ab=$out.Create(group,cn=Rooman) $ab.put(sAMAccountname,Rooman) $ab.setinfo()

To Enable Win PS script Execution


Set-ExecutionPolicy RemoteSigned

Importing users from a DB with Win Power Shell NewUsers.csv


cn,sAMAccountName,FirstName,LastName Naveen Krishna,naveen.krishna,Naveen,Krishna Gowri Shankar,gowri.shankar,Gowri,Shankar (VBS) $dataSource=import-csv "NewUsers.csv" (incomplete)

Das könnte Ihnen auch gefallen