Hi together..
i have the Problem that i need to maintain Groups in all Sub Locations just adding on dailybase all Users to a special Group... my Problem is that i need to maintain these Groups in 5 Domains in this Forrest.. arround 300 Groups at all.. so i created a script in Powershell (basic knowledge ) The Script works in my case but what is not working is that after login to the DOmain it will switch back to the normal Usercontext.. Using in this case an Enterprice Admin is not an option because the script will later run multiple Times everyday
so what i need is an Funktion which would logon with a special Admin in each Domain doing some work (normaly with functions and disconnect thats why i use the Switch routine
Can anybody help here?
Michael
$DC = "DC1.Domain1.contoso.com","DC1.Domain2.contoso.com",
$DelegationAdmin = "Domain1\DAUser"
$TestAdmin = "Domain2\DATester"
Function LoginToDomain {
PARAM ( $Admin,
$Domain
)
if (!(Test-Path //localComputer/EncryptedFiles/encryped$Domain.txt))
{
$pass = read-host -assecurestring -prompt "Enter password for $($Domain) to encrypt: "
convertfrom-securestring $pass | out-file //localComputer/EncryptedFiles/encryped$Domain.txt -Force
}
$tt = ConvertTo-SecureString (gc "//localComputer/EncryptedFiles/encryped$Domain.txt")
connect-QADService -Service $Domain -ConnectionAccount $Admin -ConnectionPassword $tt
}
ForEach ($which in $DC) {
$DomName = ($which | Select-Object -unique -First 2).Split(".")[1]
#Connect-QADService -Service $which | Out-Null
Switch ($DomName){"Domain1" { $OU = "OU=delegation,DC=Domain1,DC=contoso,DC=com"
LoginToDomain -Admin $DelegationAdmin -Domain $which
$LocationList = Get-QADObject -SizeLimit 0 -SearchRoot $OU -SearchScope "OneLevel" -Type "OrganizationalUnit" `
| % {Get-QADObject -SizeLimit 0 -SearchRoot $_.DN -Type "OrganizationalUnit" -SearchScope "OneLevel" | ? {$_.Name -notmatch "move"}| ?{$_.Name -notmatch "au0*"}} `
| ?{$_.Name -notmatch "cda*"}| ?{$_.Name -notmatch "tst*"}| ?{$_.Name -notmatch "back*"}| Sort-Object "Name"
ForEach ($Loc in $LocationList){
write-host $Loc -ForegroundColor DarkGreen
####
# do the additional functions
###
}
$Loc = " "
$OU = " "
$DomName = " "
$LocationList = " "
}"Domain2" { $OU = "OU=Testing,DC=Domain2,DC=contoso,DC=com"
LoginToDomain -Admin $TestAdmin -Domain $which
$LocationList = Get-QADObject -SizeLimit 0 -SearchRoot $OU -SearchScope "OneLevel" -Type "OrganizationalUnit" `
| % {Get-QADObject -SizeLimit 0 -SearchRoot $_.DN -Type "OrganizationalUnit" -SearchScope "OneLevel" | ? {$_.Name -notmatch "move"}| ?{$_.Name -notmatch "au0*"}} `
| ?{$_.Name -notmatch "cda*"}| ?{$_.Name -notmatch "tst*"}| ?{$_.Name -notmatch "back*"}| Sort-Object "Name"
ForEach ($Loc in $LocationList){
write-host $Loc -ForegroundColor DarkGreen
####
# do the additional functions
###
}
$Loc = " "
$OU = " "
$DomName = " "
$LocationList = " "
}
default {Write-Host "$($DomName) - Domain not managed or found" -ForegroundColor Red}
}
}