Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Windows Powershell, Windows Server | 4 Comments | 4,352 views | 22/08/2009 10:28
Are you kidding? How can I use “Remove-ADUser” to delete an user from Active Directory if there is no “-force” switch? Simply, it is for blocking automation scripts. We have so many IIS users in Active Directory. What should we do? Should we hire a new guy to manage users? I quit to use Powershell v2 AD modules for a while.
Update: You can assign $false to confirm parameter:
Remove-ADUser "User1" -Confirm:$False |
Remove-ADUser "User1" -Confirm:$False
Thanks to Shay Levi.
Posted in Windows Powershell | No Comment | 2,878 views | 18/08/2009 12:55
I created this script to create active directory user with Powershell.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| function Add-ADUser
{
param ($UserID, $HostID, $CustomerID, $FirstName, $LastName, $Password, $CustomerOU)
$FQDN = (Get-ADInfo).FQDN
$ADDomain = (Get-ADInfo).Domain
$CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
$CheckHostingOU = Check-HostingOU -HostID "$HostID" -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
$CustomerOU = [ADSI] "LDAP://OU=$HostID,OU=$CustomerID,$CustomerOU,$FQDN"
$PrincipalName = $UserID + "@" + $ADDomain
$AddADUser = $CustomerOU.Create("User","CN=$UserID")
$AddADUser.Put("GivenName", "$FirstName")
$AddADUser.Put("SN", "$LastName")
$AddADUser.Put("Description", "$FirstName $LastName")
$AddADUser.Put("sAMAccountName", "$UserID")
$AddADUser.Put("userPrincipalName", "$PrincipalName")
$AddADUser.Put("DisplayName", "$FirstName $LastName")
$AddADUser.SetInfo()
$AddADUser.SetPassword("$Password")
$AddADUser.SetInfo()
$AddADUser.Psbase.Invokeset("AccountDisabled", "False")
$AddADUser.SetInfo()
$AddADUser.Put("userAccountControl", "66080")
$AddADUser.SetInfo()
If(!$AddADUser)
{
Write-Host "An Error Occurred."
$Status = "0"
Return
}
$Status = "1"
} |
function Add-ADUser
{
param ($UserID, $HostID, $CustomerID, $FirstName, $LastName, $Password, $CustomerOU)
$FQDN = (Get-ADInfo).FQDN
$ADDomain = (Get-ADInfo).Domain
$CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
$CheckHostingOU = Check-HostingOU -HostID "$HostID" -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
$CustomerOU = [ADSI] "LDAP://OU=$HostID,OU=$CustomerID,$CustomerOU,$FQDN"
$PrincipalName = $UserID + "@" + $ADDomain
$AddADUser = $CustomerOU.Create("User","CN=$UserID")
$AddADUser.Put("GivenName", "$FirstName")
$AddADUser.Put("SN", "$LastName")
$AddADUser.Put("Description", "$FirstName $LastName")
$AddADUser.Put("sAMAccountName", "$UserID")
$AddADUser.Put("userPrincipalName", "$PrincipalName")
$AddADUser.Put("DisplayName", "$FirstName $LastName")
$AddADUser.SetInfo()
$AddADUser.SetPassword("$Password")
$AddADUser.SetInfo()
$AddADUser.Psbase.Invokeset("AccountDisabled", "False")
$AddADUser.SetInfo()
$AddADUser.Put("userAccountControl", "66080")
$AddADUser.SetInfo()
If(!$AddADUser)
{
Write-Host "An Error Occurred."
$Status = "0"
Return
}
$Status = "1"
}
You can find included functions with search.
Posted in Windows Powershell, Windows Server | No Comment | 4,597 views | 18/08/2009 11:53
This is my simple Powershell script to create organizational units with Powershell.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| function Add-CustomerOU
{
param ($CustomerID, $CustomerOU)
$CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
If($CheckCustomerOU.Status -eq "0")
{
$FQDN = (Get-ADInfo).FQDN
$CustomerOU = [ADSI] "<a href="ldap://$CustomerOU,$FQDN">LDAP://$CustomerOU,$FQDN</a>"
$CreateOU = $CustomerOU.Create("OrganizationalUnit", "OU=$CustomerID")
$CreateOU.SetInfo()
If(!$CreateOU)
{
Write-Host "An Error Occurred."
}
}
Else
{
Write-Host "Organizational Unit already exist on the Server" | Out-Null
$Status = "1"
}
} |
function Add-CustomerOU
{
param ($CustomerID, $CustomerOU)
$CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
If($CheckCustomerOU.Status -eq "0")
{
$FQDN = (Get-ADInfo).FQDN
$CustomerOU = [ADSI] "<a href="ldap://$CustomerOU,$FQDN">LDAP://$CustomerOU,$FQDN</a>"
$CreateOU = $CustomerOU.Create("OrganizationalUnit", "OU=$CustomerID")
$CreateOU.SetInfo()
If(!$CreateOU)
{
Write-Host "An Error Occurred."
}
}
Else
{
Write-Host "Organizational Unit already exist on the Server" | Out-Null
$Status = "1"
}
}
This script creates an organizational unit under another one using some arguments.
Posted in Exchange Server | No Comment | 2,522 views | 18/08/2009 10:38
Finally, we can test Exchange Server 2010 RC. Now, Exchange Server 2010 is fully compatible with Windows Server 2008 R2 RC.
http://www.microsoft.com/exchange/2010/en/us/try-it.aspx
You can reach download link from Exchange’s Official Page.
Edit: There is no way to download Exchange Server 2010 RC. I think we’ll wait for a while.
Edit: Download link is now available on Microsoft Download Center.
Posted in Windows Powershell, Windows Server | No Comment | 2,805 views | 17/08/2009 10:59
Today, I created a Powershell script to check a service status and if it is stopped, that starts it.
1
2
3
4
5
| $Status = (Get-Service MEMTAS).Status
If ($Status -eq "Stopped")
{
Start-Service MEMTAS
} |
$Status = (Get-Service MEMTAS).Status
If ($Status -eq "Stopped")
{
Start-Service MEMTAS
}
Then add this to Cronjob and set it to run every 5 minutes. MEMTAS is a service name of Mail Enable.
Posted in Windows Powershell, Windows Server | No Comment | 3,907 views | 16/08/2009 20:28
This is my custom Powershell script to check OU in Active Directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| function Check-CustomerOU
{
param ($CustomerID, $CustomerOU)
$FQDN = (Get-ADInfo).FQDN
$CustomerOU = [ADSI] "LDAP://OU=$CustomerID,$CustomerOU,$FQDN"
If(!$CustomerOU)
{
Write-Host "No such Organizational Unit on the Server" | Out-Null
$Status = "0"
}
Else
{
Write-Host "Organizational Unit exist on the Server" | Out-Null
$Status = "1"
}
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Status $Status
Write-Output $Results
} |
function Check-CustomerOU
{
param ($CustomerID, $CustomerOU)
$FQDN = (Get-ADInfo).FQDN
$CustomerOU = [ADSI] "LDAP://OU=$CustomerID,$CustomerOU,$FQDN"
If(!$CustomerOU)
{
Write-Host "No such Organizational Unit on the Server" | Out-Null
$Status = "0"
}
Else
{
Write-Host "Organizational Unit exist on the Server" | Out-Null
$Status = "1"
}
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Status $Status
Write-Output $Results
}
As you see, it is too easy to check an Active Directory OU with Powershell.
Posted in Windows Powershell, Windows Server | 1 Comment | 2,743 views | 16/08/2009 20:16
I needed to check an user from Active Directory with Powershell so I wrote this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| function Check-ADUser
{
param ($UserID)
$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(&(objectClass=user)(sAMAccountName= $UserID))"
$CheckADUser = ($Searcher.Findall()).Count
If($CheckADUser -eq "0")
{
Write-Host "No such user on the Server" | Out-Null
$Status = "0"
}
Else
{
Write-Host "User exist on the Server" | Out-Null
$Status = "1"
}
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Status $Status
Write-Output $Results
} |
function Check-ADUser
{
param ($UserID)
$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(&(objectClass=user)(sAMAccountName= $UserID))"
$CheckADUser = ($Searcher.Findall()).Count
If($CheckADUser -eq "0")
{
Write-Host "No such user on the Server" | Out-Null
$Status = "0"
}
Else
{
Write-Host "User exist on the Server" | Out-Null
$Status = "1"
}
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Status $Status
Write-Output $Results
}
Usage Sample:
$Status = (Check-ADUser -UserID ysfozy).Status |
$Status = (Check-ADUser -UserID ysfozy).Status
This script can search user from Active Directory and show you results.
|