This article is influenced by how to do things via c# but lacks of fundamentals regarding PowerShell. Firstly, that’s not the correct way to set a script-level variable. You should simply use PowerShell-way: $script:number. Secondly, this approach is not recommended for writing any kind of PowerShell code, as it is prone to mistakes. Lastly, the function names are a mess as they don’t use verb-noun format and they don’t actually do what they are called. A much better approach would be:
1) You aren’t doing any calculations via Calculate function
function Set-ValueTo50
{
50
}
$num = Set-ValueTo50
$num
2.1) Not optimal
function Set-BhawanaRathore
{
$script:FirstName = “Bhawana”
$script:LastName = “Rathore”
}
$FirstName = “Bijay”
$LastName = “Sahoo”
Write-Host “$FirstName $LastName”
Set-BhawanaRathore $FirstName $LastName
Write-Host $firstname” “$lastname
2.2) Optimized
function Set-FirstNameBhawana
{
“Bhawana”
}
function Set-LastNameRathore
{
“Rathore”
}
$FirstName = “Bijay”
$LastName = “Sahoo”
Write-Host “$FirstName $LastName”
$FirstName = Set-FirstNameBhawana
$LastName = Set-LastNameRathore
Write-Host $firstname” “$lastname
]]>