Anonymous
Is there a problem with PS Code on TechNet
0
PEOPLE
Referencing http://technet.microsoft.com/en-us/magazine/2009.05.powershell.aspx#id0030048
My question is about:
Function CreateHomeFolder {
Param($userinfo)
$server1 = 'a','b','c','d'
$server2 = 'e','f','g','h'
Switch ($userinfo['samAccountName'].
substring(0,1).tolower()) {
{ $server1 –contains $_ }
{ $homeserver = '\\homeserver1\'; break; }
{ $server2 –contains $_ }
{ $homeserver = '\\homeserver2\'; break; }
}
Mkdir ($homeserver + '\$Homes\' + $userinfo['samAccountName'])
}
I think that there is a problem somewhere after "Switch". Can you verify? Also, is this series of atricles applicable to PS v2?
Replies
To take your second question first, anything written for v1 will work for v2. That's not to say you couldn't do this more easily with v2, but it'll still work.
And to answer the first question - it doesn't look like there's a problem. Here's what it's doing: It's switching based on the first character of the user's samAccountName, which is forced to lowercase.
The first switch condition checks to see if $server1 (which is a collection, of a,b,c,d) contains the switch base (first character of the user's name).
So the idea is that people whose names start with a,b,c, or d go into the first server, and their $homeserver variable gets set to homeserver1.
Seems to be running okay for me; is it generating an error or something for you?







