Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

many functions inside one if statement

$
0
0

Hi friends

i have created a customized powershell profile (profile.ps1 file.)

i will use this file in servers which some of them are Domain controller & some of them are not.

since there are many Active directory related functions inside this file,  to avoid errors when loading this profile in non domain controller servers, i want to use a condition so check if the current server is Domain controller, then many AD-Related functions be loaded.

there are about 20 functions which takes about 200 lines. 

is it the best practice to put all of them inside an if statement?

for example is it standard to write them as following?

 

$ADService = Get-Service -Name NTDS

If ($ADService) {

function1 createOUs {

many lines of code here

}

function2 create users {

many lines of code here

}

function3 create GPOs{

many lines of code here

}

# and many other functions....

.

.

.

}    #-----> closing if statement

or its better to put the mentioned condition  "if ($service)" as the first line inside each function?

 

thanks in advanced

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles