I have a simple PS script which modifies an AD account. How do I put in the body of the script which account to use as the modifier?


my script looks like:

param($username, $psserver, $type, $status, $unit)
#
if(@(get-module | where-object {$_.name -eq "activedirectory"} ).count -eq 0) {import-module activedirectory}
#

$erroractionpreference = "stop"

if ($username -eq $null) {

$x= "a username parameter must provided."
$x
exit
}

if ($psserver -eq $null) {
    $x= "the qualified name of domain controller must provided."
    $x
    exit
}

#
$objdomain = new-object system.directoryservices.directoryentry
$objsearcher = new-object system.directoryservices.directorysearcher
$objsearcher.searchroot = "ldap://" + $psserver
$objsearcher.pagesize = 1000
$objsearcher.filter = "(&(objectclass=user)(samaccountname= $username))"
$objsearcher.searchscope = "subtree"

$user = $objsearcher.findone()
if ($user -eq $null -or $user.count -eq 0) {
    $x = "no user found username=" + $username
    $x
    exit
}
$userdn = $user.path
$userdn
$userobj = [adsi]$userdn
$x = $userobj.put("extensionattribute2","change")
$x = $userobj.setinfo()
$x

this works if script run privileged user e.g. member of account operators group. need run script ordinary user. know admin account name/password. how arrange $userobj.put() , $userobj.setinfo() actioned admin user, if script run ordinary account.

i ask because these scripts started within process , process started non admin ad account.

help!!

*hh

i agree both!
storing password and/or give away, same putting key under doormat. is normally a security suicide!
if working in big enterprise process apply rights is dog slow and if gain rights the key , account management, the need over!
please keep in mind! secure computer computer without power! must scared finds power socket ;-)) !
security illusion! stays few seconds, until finds hole! 

so can only put security barrier high possibel!
if have dirty stuff, make right , on hardest way ever possible!

my 0.02 cent ....


please click “mark answer” if post answers question , click vote help if post helps you.
bitte markiere hilfreiche beiträge von mir als hilfreich und beiträge die deine frage ganz oder teilweise beantwortet haben als antwort.
powershell blog http://www.admin-source.info
[string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Global Catalog ?

mailing list

Global Catalog