$_.SamAccountName

Guys.

I have this script that been put together in a few different ways but i think i have something that is going to work. The script will connect to each AD accounts it finds in an OU, then match Attribute1 and then switch.

The issue that im having is that i cant get it to pick up the user name form the command below. Just using $_ works but it displays Domain\Username where reallyu i just want the SamAccountName.

I have been banging my head and trying different things but cant quite get it to work. Any ideas?

write-host $profilepath\$_.SamAccountName

----

The script is below

-----------------------------

Connect-QADService -Service "SERVER-NAME -Proxy

$OUSelected = "OU-NAME"

Get-QADUser -SizeLimit 0 -IncludedProperties "Attribute1" -SearchRoot $OUSelected |
ForEach-Object{
    $siteid = switch ($_."Attribute1") {
        'CH' { $ProfilePath = "\\PATH1"}
        'EU' { $ProfilePath = "\\PATH2"}
        'HK' { $ProfilePath = "\\PATH3"}
        'US' { $ProfilePath = "\\PATH4"}
    
        
        default { 'No site' }
    }
    write-host $profilepath\$_.SamAccountName
}
July 23rd, 2015 9:51am

Hi,

You could do something like this:

$str = 'DOMAIN\username'
$strFixed = $str.Split('\')[-1]

$strFixed


Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 10:01am

Thank you Mike. The subexpression did the trick on this one.
July 23rd, 2015 10:07am

Cheers, you're very welcome. Glad it worked out.
Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 10:14am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics