Comma Before Parentheses in Variable AssignmentSetting Windows PowerShell environment variablesWhy does invoking a Powershell script block with .Invoke() return a collection?How do I concatenate strings and variables in PowerShell?How do I get Powershell to output Get-ADUser -Filter * as comma delimited?Azure PowerShell - Object reference not set to an instance of an objectPowershell script to remove line of text from files in folderPowershell Regex to match everything after the first occurrence of a stringNeed Help assigning an embedded Object to a parent Object in a PowerShell scriptReturn Value of a function is not being assigned to the variable in powershellexecute a command before a parameters processing

Why was the LRV's speed gauge displaying metric units?

Why does the Eurostar not show youth pricing?

Problem with Eigenvectors

Is SecureRandom.ints() secure?

A variant of the Multiple Traveling Salesman Problem

Self-deportation of American Citizens from US

Why does Canada require bilingualism in a lot of federal government posts?

A cubeful of three-dimensional devilry

How did the SysRq key get onto modern keyboards if it's rarely used?

Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?

8086 stack segment and avoiding overflow in interrupts

If you inherit a Roth 401(k), is it taxed?

How do I find the FamilyGUID of an exsting database

What would the United Kingdom's "optimal" Brexit deal look like?

Should I accept an invitation to give a talk from someone who might review my proposal?

Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?

What are the closest international airports in different countries?

What clothes would flying-people wear?

Golden Guardian removed before death related trigger

What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?

To find islands of 1 and 0 in matrix

GNU sort stable sort when sort does not know sort order

How to efficiently shred a lot of cabbage?



Comma Before Parentheses in Variable Assignment


Setting Windows PowerShell environment variablesWhy does invoking a Powershell script block with .Invoke() return a collection?How do I concatenate strings and variables in PowerShell?How do I get Powershell to output Get-ADUser -Filter * as comma delimited?Azure PowerShell - Object reference not set to an instance of an objectPowershell script to remove line of text from files in folderPowershell Regex to match everything after the first occurrence of a stringNeed Help assigning an embedded Object to a parent Object in a PowerShell scriptReturn Value of a function is not being assigned to the variable in powershellexecute a command before a parameters processing






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm using the S.DS.P PowerShell module in a PowerShell script of mine. In it, I have to create the following object:



$ADUserEntry = @"distinguishedName"=$null;"objectClass"=$null;"sAMAccountName"=$null;"unicodePwd"=$null;"userAccountControl"=0;


In the documentation of the module, it's stated that I have to do the following assignment to the unicodePwd field of a variable created using this object:



$obj.unicodePwd = ,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]]);


Notice how there's a comma before the first parentheses. What is that comma doing there?










share|improve this question



















  • 2





    it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

    – Lee_Dailey
    Mar 26 at 20:59

















2















I'm using the S.DS.P PowerShell module in a PowerShell script of mine. In it, I have to create the following object:



$ADUserEntry = @"distinguishedName"=$null;"objectClass"=$null;"sAMAccountName"=$null;"unicodePwd"=$null;"userAccountControl"=0;


In the documentation of the module, it's stated that I have to do the following assignment to the unicodePwd field of a variable created using this object:



$obj.unicodePwd = ,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]]);


Notice how there's a comma before the first parentheses. What is that comma doing there?










share|improve this question



















  • 2





    it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

    – Lee_Dailey
    Mar 26 at 20:59













2












2








2


1






I'm using the S.DS.P PowerShell module in a PowerShell script of mine. In it, I have to create the following object:



$ADUserEntry = @"distinguishedName"=$null;"objectClass"=$null;"sAMAccountName"=$null;"unicodePwd"=$null;"userAccountControl"=0;


In the documentation of the module, it's stated that I have to do the following assignment to the unicodePwd field of a variable created using this object:



$obj.unicodePwd = ,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]]);


Notice how there's a comma before the first parentheses. What is that comma doing there?










share|improve this question














I'm using the S.DS.P PowerShell module in a PowerShell script of mine. In it, I have to create the following object:



$ADUserEntry = @"distinguishedName"=$null;"objectClass"=$null;"sAMAccountName"=$null;"unicodePwd"=$null;"userAccountControl"=0;


In the documentation of the module, it's stated that I have to do the following assignment to the unicodePwd field of a variable created using this object:



$obj.unicodePwd = ,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]]);


Notice how there's a comma before the first parentheses. What is that comma doing there?







powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 20:32









Gonçalo LourençoGonçalo Lourenço

7751 gold badge5 silver badges17 bronze badges




7751 gold badge5 silver badges17 bronze badges










  • 2





    it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

    – Lee_Dailey
    Mar 26 at 20:59












  • 2





    it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

    – Lee_Dailey
    Mar 26 at 20:59







2




2





it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

– Lee_Dailey
Mar 26 at 20:59





it's the comma operator. [grin] it makes an array with the item to the left as an object in the new array. that can be used to prevent the automatic unrolling of an array by wrapping the 1st array in a 2nd one ... and the 2nd one is the one that gets unwrapped. you can see the MS docs on that here ... about_Operators | Microsoft Docs — docs.microsoft.com/en-us/powershell/module/…

– Lee_Dailey
Mar 26 at 20:59












1 Answer
1






active

oldest

votes


















1














As Lee_Daily has pointed out, what you're seeing is the unary form of the (unfortunately named) "comma operator", i.e., PowerShell's array-construction operator.



The unary form creates a single-element array that wraps its (one and only) operand; the array's type is [object[]], as usual in PowerShell:



$arr = , 'foo' # wrap string 'foo' in a single-element array
$arr.GetType().Name # the array's type -> 'Object[]'
$arr[0].GetType().Name # the type of the array's one and only element -> 'String'


Note that while you can even wrap arrays that way, PowerShell's operator-precedence rules require a literal array operand to be enclosed in (...):



# OK - wraps array 1, 2 in a single-element array.
$arr = , (1, 2)

# !! DOES SOMETHING DIFFERENT:
# Creates a 2-element array whose 1st element is integer 1 wrapped in a
# single-element array
$arr = , 1, 2


The binary form constructs an array from the operands, as expected:



$arr = 1, 2, 3 # 3-element array whose elements are integers 1 and 2 and 3



As an aside, re the specific command shown:




,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]])




Neither , nor -as [byte[]] are needed in this scenario, because
[System.Text.Encoding]::Unicode.GetBytes() directly returns a [byte[]] array.






share|improve this answer

























  • My pleasure, @GonçaloLourenço; glad to hear it was helpful.

    – mklement0
    Mar 26 at 21:55










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365765%2fcomma-before-parentheses-in-variable-assignment%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














As Lee_Daily has pointed out, what you're seeing is the unary form of the (unfortunately named) "comma operator", i.e., PowerShell's array-construction operator.



The unary form creates a single-element array that wraps its (one and only) operand; the array's type is [object[]], as usual in PowerShell:



$arr = , 'foo' # wrap string 'foo' in a single-element array
$arr.GetType().Name # the array's type -> 'Object[]'
$arr[0].GetType().Name # the type of the array's one and only element -> 'String'


Note that while you can even wrap arrays that way, PowerShell's operator-precedence rules require a literal array operand to be enclosed in (...):



# OK - wraps array 1, 2 in a single-element array.
$arr = , (1, 2)

# !! DOES SOMETHING DIFFERENT:
# Creates a 2-element array whose 1st element is integer 1 wrapped in a
# single-element array
$arr = , 1, 2


The binary form constructs an array from the operands, as expected:



$arr = 1, 2, 3 # 3-element array whose elements are integers 1 and 2 and 3



As an aside, re the specific command shown:




,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]])




Neither , nor -as [byte[]] are needed in this scenario, because
[System.Text.Encoding]::Unicode.GetBytes() directly returns a [byte[]] array.






share|improve this answer

























  • My pleasure, @GonçaloLourenço; glad to hear it was helpful.

    – mklement0
    Mar 26 at 21:55















1














As Lee_Daily has pointed out, what you're seeing is the unary form of the (unfortunately named) "comma operator", i.e., PowerShell's array-construction operator.



The unary form creates a single-element array that wraps its (one and only) operand; the array's type is [object[]], as usual in PowerShell:



$arr = , 'foo' # wrap string 'foo' in a single-element array
$arr.GetType().Name # the array's type -> 'Object[]'
$arr[0].GetType().Name # the type of the array's one and only element -> 'String'


Note that while you can even wrap arrays that way, PowerShell's operator-precedence rules require a literal array operand to be enclosed in (...):



# OK - wraps array 1, 2 in a single-element array.
$arr = , (1, 2)

# !! DOES SOMETHING DIFFERENT:
# Creates a 2-element array whose 1st element is integer 1 wrapped in a
# single-element array
$arr = , 1, 2


The binary form constructs an array from the operands, as expected:



$arr = 1, 2, 3 # 3-element array whose elements are integers 1 and 2 and 3



As an aside, re the specific command shown:




,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]])




Neither , nor -as [byte[]] are needed in this scenario, because
[System.Text.Encoding]::Unicode.GetBytes() directly returns a [byte[]] array.






share|improve this answer

























  • My pleasure, @GonçaloLourenço; glad to hear it was helpful.

    – mklement0
    Mar 26 at 21:55













1












1








1







As Lee_Daily has pointed out, what you're seeing is the unary form of the (unfortunately named) "comma operator", i.e., PowerShell's array-construction operator.



The unary form creates a single-element array that wraps its (one and only) operand; the array's type is [object[]], as usual in PowerShell:



$arr = , 'foo' # wrap string 'foo' in a single-element array
$arr.GetType().Name # the array's type -> 'Object[]'
$arr[0].GetType().Name # the type of the array's one and only element -> 'String'


Note that while you can even wrap arrays that way, PowerShell's operator-precedence rules require a literal array operand to be enclosed in (...):



# OK - wraps array 1, 2 in a single-element array.
$arr = , (1, 2)

# !! DOES SOMETHING DIFFERENT:
# Creates a 2-element array whose 1st element is integer 1 wrapped in a
# single-element array
$arr = , 1, 2


The binary form constructs an array from the operands, as expected:



$arr = 1, 2, 3 # 3-element array whose elements are integers 1 and 2 and 3



As an aside, re the specific command shown:




,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]])




Neither , nor -as [byte[]] are needed in this scenario, because
[System.Text.Encoding]::Unicode.GetBytes() directly returns a [byte[]] array.






share|improve this answer













As Lee_Daily has pointed out, what you're seeing is the unary form of the (unfortunately named) "comma operator", i.e., PowerShell's array-construction operator.



The unary form creates a single-element array that wraps its (one and only) operand; the array's type is [object[]], as usual in PowerShell:



$arr = , 'foo' # wrap string 'foo' in a single-element array
$arr.GetType().Name # the array's type -> 'Object[]'
$arr[0].GetType().Name # the type of the array's one and only element -> 'String'


Note that while you can even wrap arrays that way, PowerShell's operator-precedence rules require a literal array operand to be enclosed in (...):



# OK - wraps array 1, 2 in a single-element array.
$arr = , (1, 2)

# !! DOES SOMETHING DIFFERENT:
# Creates a 2-element array whose 1st element is integer 1 wrapped in a
# single-element array
$arr = , 1, 2


The binary form constructs an array from the operands, as expected:



$arr = 1, 2, 3 # 3-element array whose elements are integers 1 and 2 and 3



As an aside, re the specific command shown:




,([System.Text.Encoding]::Unicode.GetBytes("$randomPassword") -as [byte[]])




Neither , nor -as [byte[]] are needed in this scenario, because
[System.Text.Encoding]::Unicode.GetBytes() directly returns a [byte[]] array.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 21:21









mklement0mklement0

151k25 gold badges272 silver badges312 bronze badges




151k25 gold badges272 silver badges312 bronze badges















  • My pleasure, @GonçaloLourenço; glad to hear it was helpful.

    – mklement0
    Mar 26 at 21:55

















  • My pleasure, @GonçaloLourenço; glad to hear it was helpful.

    – mklement0
    Mar 26 at 21:55
















My pleasure, @GonçaloLourenço; glad to hear it was helpful.

– mklement0
Mar 26 at 21:55





My pleasure, @GonçaloLourenço; glad to hear it was helpful.

– mklement0
Mar 26 at 21:55








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365765%2fcomma-before-parentheses-in-variable-assignment%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현