Help with code

by Beach Boy at 2012-09-20 11:47:08

I am learning Powershell and came accross this code that would help if we could figure out how to populate the “Name” attribute. Could you please advise how to get this script to work properly? … omain.html

Thank you.
by poshoholic at 2012-09-21 07:59:53
Can you be more specific with what you are after? That script already allows you to run it and specify the samAccountName for the user you want to modify. If that’s not what you need, what exactly are you trying to accomplish, what have you figured out so far, and what are the specific issues you are running into?
by Beach Boy at 2012-09-21 09:08:09
My confussion is that where do I specify the samAccountName wanting to be checked? When I run the script as is, it just skips straight to the end giving me a result of “User provided: , is not in the Active Directory”. Any help would be appreciated.
by RichardSiddaway at 2012-09-21 09:46:31
$name refers to the name of the module you are attempting to load

$AD = "ActiveDirectory"
Function Get-MyModule {
if(-not(Get-Module -name $name)) {
if(Get-Module -ListAvailable | Where-Object { $ -eq $name }) {
Import-Module -Name $name
} else {
Get-MyModule -name $AD

I’ve highlighted the relevant parts of the code
by Beach Boy at 2012-09-21 10:17:20
So where in the script does the samAccountName wanting to be checked get called in “ActiveDirectory”? How does the script know what account to check to return the PassWord Expiration date information?
by poshoholic at 2012-09-21 18:34:32
If you look through that script you should see that they are using $args[0] to assign to another variable and then they use that variable as the samAccountName. That means that you should be able to pass in the samAccountName of the user you want to check as the first parameter. Something like this:
& C:\test.ps1 kmunro
That assumes the script would be called test.ps1, stored at the root of C, and that you would want to use a samAccountName of kmunro.