Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Value of variable disappears after function call

$
0
0

In my script, I have this function call here:

 Write-Host "About to call generate-password with length as $length" Generate-Password($method, [int]$length, $useSpecialCharacters) 

In the console window, this outputs the correct value for $length (whatever the user specifies)

Yet inside the function, the value disappears completely.

function Generate-Password ($method, [int] $length, $useSpecialCharacters){ Write-Host "In Generate-Password. length is $length" #at this point the $length variable gets cleared. 

$method (a string) passes through just fine, as does $useSpecialCharacters (either $true or $false) passes through just fine too. For some reason, $length always ends up as either blank, or 0 after I specify [int] before $length

Does anyone know why this might be?

submitted by /u/very_bad_programmer
[link] [comments]

The post Value of variable disappears after function call appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images