Variables in modules in PowerShell

Function SetSQLServerAddr ([string] $name)
{
    $SQLServer = $name
}

That creates a new local $SQLServer in the scope of that function.

If you want to update a variable at module (.psm1) scope then you need to prefix the name to indicate that:

Function SetSQLServerAddr ([string] $name)
{
    $script:SQLServer = $name
}

For more on scopes see get-help about_scopes.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)