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

using multiple functions inside if statement

$
0
0

hi friends

i am not expert in powershell & i don't know whether i am on the right way about this quation:

i have some domain controllers & some Non-Domain controller servers in my lab.

i have created two profile.ps1 file, one for Domain controllers & one for other servers.

there are some settings which will apply to both group & some settings which are specific to one of these groups.

for those settings which apply to both groups, its cumbersome to edit two files each time (for example when i need to add new desired settings into profile.ps1), so i have decided to create only a single profile.ps1 & copy that in both groups.

now the problem is, for my previous DC specific profile.ps1, i had created many functions which were related to Active directory.

now in this new profile.ps1, what is the best method ?

for example it it possible to define an if statement & inside that, create many functions & at the end, close the if statement?

i mean something like this:

$ADService = Get-Service -Name NTDS

If (($ADService) -and ($ADService.status -eq 'Running')) {

ipmo activedirectory

function MyDomainpwdsimple {

Get-Addomain | set-addefaultdomainpasswordpolicy -complexityenabled 0 `

-minpasswordlength 0 -maxpasswordage 1000.0:0:0 -minpasswordage 0 `

-passwordhistorycount 0 -ea ignore; gpupdate /target:computer }

} 

function MyRemoveGPOs {

Get-GPO -All | where {$_.Displayname -notmatch '^Default'} | 

Remove-GPO -confirm:0

}

}

 

?????????

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles