This PowerShell script can be used to add a computer to security group in Active Directory. I have used the same logic in this Update Group Membership–PowerShell Script also.
Script:
Input file (computers.csv) contain computer names in the following format:
17 comments:
I am trying to use this script. I created a csv file called Sophos Update. I adjusted the script to reflect the file location of the file and also the AD environment to which I am trying to query and add the computer accounts to a group called Sophos Update. However it wont work. I am just seeing the code showing up on the screen and the computer accounts are not been added.
Here is the adjustments I made
#
#
#
#
Clear
$InputfileC = "C:\Scripts\Sophos Update.csv"
$OutputFile = New-item -type file -Name ("Output1_$(Get-Date -f MM-dd-yyyy_hh-mm-ss).csv") -force
"sAMAccountName`t`tCurrentValue" | Out-File $OutputFile -append -encoding ASCII
$CGroupName = [ADSI]"LDAP://CN=Sophos Update,OU=Groups,DC=corp,DC=byramhealthcare,DC=com"
{
Import-CSV $Inputfilec | % {
$ComputerN = $_.ComputerName
$ComputerN = $ComputerN + "$"
$ObjFilter = "(&(Objectclass=Computer)(samaccountName=$ComputerN))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 5000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://DC=corp,DC=byramhealthcare,DC=com"
$AllObj = $objSearch.FindOne()
$objItemS = $AllObj.Properties
$AllObj
$CompDN = $objItemS.distinguishedname
$Comp = [ADSI] "LDAP://$CompDN"
Write-Host "Updating Appsense Group Membership. Adding Computer $ComputerN " -Nonewline
If ($CGroupName.IsMember($Comp.AdsPath) -eq $False)
{
$CGroupName.Add($Comp.AdsPath)
"$ComputerN`t`tUpdated" | Out-File $OutputFile -append -encoding ASCII
Write-Host "Done!" -ForegroundColor Blue
}
Else
{Write-Host "Already Exist"-ForegroundColor Red
"$ComputerN`t`tAlready Exist" | Out-File $OutputFile -append -encoding ASCII
}
}
}
Here is the adjustments I made
#
#
#
#
Clear
$InputfileC = "C:\Scripts\Sophos Update.csv"
$OutputFile = New-item -type file -Name ("Output1_$(Get-Date -f MM-dd-yyyy_hh-mm-ss).csv") -force
"sAMAccountName`t`tCurrentValue" | Out-File $OutputFile -append -encoding ASCII
$CGroupName = [ADSI]"LDAP://CN=Sophos Update,OU=Groups,DC=corp,DC=byramhealthcare,DC=com"
{
Import-CSV $Inputfilec | % {
$ComputerN = $_.ComputerName
$ComputerN = $ComputerN + "$"
$ObjFilter = "(&(Objectclass=Computer)(samaccountName=$ComputerN))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 5000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://DC=corp,DC=byramhealthcare,DC=com"
$AllObj = $objSearch.FindOne()
$objItemS = $AllObj.Properties
$AllObj
$CompDN = $objItemS.distinguishedname
$Comp = [ADSI] "LDAP://$CompDN"
Write-Host "Updating Appsense Group Membership. Adding Computer $ComputerN " -Nonewline
If ($CGroupName.IsMember($Comp.AdsPath) -eq $False)
{
$CGroupName.Add($Comp.AdsPath)
"$ComputerN`t`tUpdated" | Out-File $OutputFile -append -encoding ASCII
Write-Host "Done!" -ForegroundColor Blue
}
Else
{Write-Host "Already Exist"-ForegroundColor Red
"$ComputerN`t`tAlready Exist" | Out-File $OutputFile -append -encoding ASCII
}
}
}
Thanks Paul Drummond for providing your version of the script.
ayam ayam
sabung ayam jago
ayam jago tarung
Gambar Ayam Sabung
Great Article
IEEE Projects on Information Security
Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Mau yang lebih ????? ayam tarung
ayam bangkok vietnam
Great Article
IEEE Projects on Information Security
Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Nikmati Bonus Menarik Dari Bolavita Sekarang...
-Nikmati Bous New member 10%
-Nikmati Bonus Cashback Hingga 10%
-Nikmati Juga Bonus jackpot Hingga Ratusan juta Rupiah Setiap harinya...
Info Lengkap Hubungi:
WA : 0812-2222-995
Line : cs_bolavita
Link : www.bolavita1.com
TERIMA KASIH ^_^
Disini menyediakan semua permainan POPULER.
Anda juga dapat deposit menggunakan PULSA XL dan TSEL Tanpa Potongan
Bisa juga di Daftarkan Dengan Akun E-money
Daftar : Museumbola
Demo Slot:
Login Museumbola
Paito Warna hk
Slot 888
Agen Casino Online
Demo Slot Pragmatic
Slot Pulsa Tanpa Potongan
Demo Slot Habanero
Alasan Kenapa Kamu Harus Bermain Judi Di Museumbola
* Permainan Lengkap dari A sampai Z
* Opsi Deposit Banyak Seperti Bank, E-Cash , PULSA
* Semua Rekening Bank termasuk Bank Daerah Bisa Di Daftarkan
* Bonus Banyak
* Deposit 2 Menit
* Withdraw 5 Menit Paling Lama
* Cs Professional 24 Jam Online
Daftar Museumbola
Link Alternatif Museumbola
Judi Bola Online
Slot pulsa tanpa potongan
Demo Slot Habanero
Post a Comment