Ying Li at myITforum.com

PowerShell & System Center

PowerShell Script to Get (Set) Logon Scripts for users of a certain group

I am currently leading an effort to Upgrade our client OS from XP to Windows 7. We decided to move away from logon script (mostly used for drive mapping & printer mapping) to Group Policy Preference.

So how we determine what logon script assigned to a particular user?

My friend Jeffery Hicks has a blog about this, I like the word “Legacy”, I have long been advocating to get rid of logon script using every opportunity I have!

PS S:\> get-qaduser -LogonScript * | sort LogonScript | select name, LogonScript

What if I want to get logon script information for users from a OU, no problem-

Get-QADUser -searchroot 'OU=whatever,DC=xyz,DC=com'|select name, logonscript

Now this always get me, what if I want to pull logon script information for users from a group? It’s a little tricky, as you can’t figure it out by simply do a get-help get-qaduser –full

After few trial and errors

PS C:\Users\yl.admin\Documents\PS> $grp = get-qadgroup 'CN=whatever1, OU=whatever2,OU=whatever3,DC=xyz,DC=com'

PS C:\Users\yl.admin\Documents\PS> get-qaduser -MemberOf $grp|select name, logonscript

Last but not least, the whole point is not just get the logon script assigned to users but to get rid of them!

PS C:\Users\yl.admin\Documents\PS> get-qaduser -MemberOf $grp|set-qaduser –logonscript “”


No Comments