Need guidance regarding Try Catch approch

Hi Team,

I m using try catch in one of my script as per the following way. Its working perfectly, but I want to confirm with you that it is a good practice or not. And if not, then please guide me little bit why not.


Try {

Get-addomaincontroller - server dc01 -ea stop

} catch {

Gsv -name adws |start-service -ea SilentlyContinue

Get-addomaincontroller - server dc01



Please note, its a sample portion of my script, which is to let you give an idea what I m doing in the script. Catch block also contains error handling, which is not written here to save time :relaxed:.

As per my environment, if 2008 dcs’ ad web service not running then the try block will fail. So I write the solution in that manner.

I already tested the same and only for this service sometimes Get-addomaincontroller is failing. Please guide me I m doing any thing bad or not.



One thing please don’t use SilentlyContinue,

there is no output from that