powershell - Filtering AD property from get-ADUser -
so writing script, in our company store users home-directory on network drives, , when leave rename directory adding .left folder name, example: "name.left" , used finding user in ad copying content of home directory property , renaming it. got far :
$name = read-host 'user name: ' $path = get-aduser $name -properties homedirectory rename-item $path {$name+".left"}
problem when home-directorys path in get-aduser gives standart get-aduser output, adds output tried using filter :
$path = get-aduser $name -properties homedirectory -filter homedirectory
and gave me error, not filter, doesn't recognize user name gave it.
now, i'm sure there way filter string in property. , feeling third line wrote might wrong as-well, that's python brain trying work powershell :) if enyone me one, appreciate it, , if can point me powershell guides nice.
edit: fixed :
$name = read-host 'user name: ' $date = read-host 'date please: ' { $path = get-aduser $name -properties homedirectory | select -expand homedirectory $newname = {$name + "lft" + $date} rename-item $path $newname write-host $name + 'changed' } while ($name -ne 'exit')
and error new name script , not string cant run, know way fix it?
rename-item : cannot evaluate parameter 'newname' because argument specified script block , there no input. script block cannot evaluated without input. @ line:6 char:19 + rename-item $path $newname + ~~~~~~~~ + categoryinfo : metadataerror: (:) [rename-item], parameterbindingexception + fullyqualifiederrorid : scriptblockargumentnoinput,microsoft.powershell.commands.renameitemcommand
edit2 fellow employee helped me out , result: needed :)
$name = read-host 'user name ' $homefolder = (get-aduser $name -properties homedirectory).homedirectory $date = get-date -uformat "%d.%m.%y" ren $homefolder -newname ($homefolder + "_lft_" + $date)
with select-object
can filter out unwanted properties. still return object tho. has handy argument named expand
return single properties value:
$path = get-aduser $name -properties homedirectory | select -expand homedirectory
Comments
Post a Comment