First off, I'm just learning powershell. There is no real reason on why I want to do this code a certain way other than exploration (plus for some reason in my head I don't feel this requires a variable, and fewer variables = good for some reason to me)
Here is what I'm trying to do. I want to set the administrator password to adm_(lowercase computer name).
I know I can do it like this:
But what I would like to do is something like:
Of course that doesn't work.
The error I get:
Any way I can condense those 3 lines down into one?
thanks.
Here is what I'm trying to do. I want to set the administrator password to adm_(lowercase computer name).
I know I can do it like this:
Code:
$a = gc env:computername
$a = $a.ToLower()
([adsi]"WinNT://localhost/AdminTest").SetPassword("adm_"+$a)
But what I would like to do is something like:
Code:
([adsi]"WinNT://localhost/AdminTest").SetPassword("adm_"+gc env:computername.ToLower())
The error I get:
You must provide a value expression on the right-hand side of the '+' operator.
At line:1 char:58
+ ([adsi]"WinNT://localhost/AdminTest").SetPassword("adm_"+ <<<< gc env:computername.ToLower())
+ CategoryInfo : ParserError:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
Any way I can condense those 3 lines down into one?
thanks.