From the course: PowerShell for SQL Server Administration

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Object reuse

Object reuse - PowerShell Tutorial

From the course: PowerShell for SQL Server Administration

Start my 1-month free trial

Object reuse

- [Instructor] So one of the things you can do in Power Shells, you can reuse object names. You can reuse variable names, which is sort of common and expected when we do programming or when we do scripting. So, objects can be reused, but things can get a little funky when we start dealing with things like scoping and various ways of creating objects. We're going to look at that as an example and so we can just try to clear some of this stuff up. So because we can reuse objects, do keep in mind that whenever we reuse an object, whatever value that variable was holding, is going to be gone and we're just going to have the new value. Now, specifically this can get kind of tricky when you start dealing with scoping. So what we mean with scoping is when we create a function, the code inside the function is going to be one scope. The code that calls that function will be another scope. So this is when things can start getting kind of tricky with how variables are going to be, not declared…

Contents