Create OU
$strCL="organizationalUnit"
$strOUName="ou=TestOU"
$objADSI=[ADSI]"LDAP://dc=fabrikam,dc=com"
$objOU=$objADSI.create($strCL,$strOUName)
$objOU.setinfo()
Create User
$strCL="User"
$strName="Cn=Erkan"
$objADSI=[ADSI]"LDAP://ou=TestOU,dc=fabrikam,dc=com"
$objUser=$objADSI.create($strCL,$strName)
$$objUser.Put("sAMAccountName","Erkan")
$objUser.setinfo()
Modify User Properties
$objUser=[ADSI]"LDAP://cn=Erkan,ou=TestOU,dc=fabrikam,dc=com"
$objUser.put("sAMAccountName","Erkan")
$objUser.put("givenName","Sezgin")
$objUser.put("DisplayName","Erkan Sezgin")
$objUser.put("telephoneNumber","216-111-1111")
$objUser.put("mail","erkan.sezgin@fabrikam.com")
$objUser.setinfo()
Other Attributes;
wwwHomePage,description,streetAddress,postOfficeBox,l,st,postalcode,CountryCode
homeDirectory,homeDrive,profilePath,scriptPath,homePhone,title
put what you want,but dont forget the $setinfo() method at the end.
Active Directory Tasks by using Powershell
how to convert your Powershell output to HTML file
Powershell has ability to save a html file for your scripts output.This gives you more flexibility to read and modify data format.
example 1
get-process | convertTo-html | set-content c:\Get-process.htm
This command gives your get-process command output to c:\get-process.htm
______________________
example 2
get-process | convertto-html -title "Get-process for this machine" -body "You can see processes of this machine" | set-content c:\get-processWithbody.htm
We add a title text and a body text to our html.
you can change the format of the html page.
-body "
"
-body " "
http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/convertto-html.mspx
Ping a host address by using Powershell
#create a ping object
$ping=New-Object net.NetworkInformation.Ping
#we gonna ping 4 times.
for ($i=0;$i -lt 4;$i++)
{
$result=$ping.send("www.google.com")
#if clause will decide whether it is ok or not.
if ($result.status -eq "Success")
{
$result.Address.ToString() + " IP address has been responding."
$result.Status
}
else{
"Failed"
}
}
Powershell Net formları giriş
[void][reflection.assembly]::LoadWithPartialName(
"System.windows.forms"
$form=new-object windows.forms.form
$form.text="Form Başlık"
$button=new-object windows.forms.button
$button.text="Click"
$button.dock="Fill"
$button.add_click({$form.close()})
$form.controls.add($button)
$form.add_shown({$form.activate()})
$form.showdialog()