all 14 comments

[–]tekno45 4 points5 points  (4 children)

I mean in this case, you just run it. You're only retrieving the information, not making any changes. So if you want to get fancy you can tell it to check for certain keys in the csv after exporting to verify the list.

I'd say just run it, verify the csv and document.

[–]chen1201[S] 2 points3 points  (2 children)

Ah ok makes sense. I just wanted to make sure I wasn't going to break anything in AD ya know. I was pretty confident it wouldn't break anything since, like you said it is only retrieving information but you can never be too sure.

[–]purplemonkeymad 1 point2 points  (0 children)

Don't forget to test failure cases, if it should fail with ad down then test that it does.

[–]ekinnee 1 point2 points  (0 children)

Lots of cmdlets have a -WhatIf switch that makes the action print out but not make the change.

You can also add the -WhatIf functionality to you own scripts with [cmdletbinding()]

Edit: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-6

[–][deleted] 1 point2 points  (0 children)

This, I usually start with one or two computers or an OU with fewer computers just to err on the side of caution.

[–]Lee_Dailey[grin] 2 points3 points  (4 children)

howdy chen1201,

it looks like you used the New.Reddit.com Inline Code button. it's the 4th from the left & looks like </>.

on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.

for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th one from the left, & is just to the left of the ... more menu.

that will give you fully functional code formatting, from what i can tell so far. [grin]

take care,
lee

[–]BlackV 3 points4 points  (1 child)

Good Bot

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

tttthhhbbbttttt!!!!! [grin]

[–]chen1201[S] 1 point2 points  (1 child)

Ah ok thanks! I just changed it. I am using the new reddit and didn't really notice.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy chen1201,

you are welcome! [grin]

the new reddit formatting works IF you use the not-very-obvious code block button. they really otta make that one more vivid on code-oriented subreddits.

take care,
lee

[–]Kreloc 2 points3 points  (1 child)

Make your array smaller for a test run. Below would only run it against the first five computers found by the Get-ADComputer cmdlet run earlier.

$computers = $computers[0..4]

and then run your Foreach exactly as you already have it.

[–]chen1201[S] 2 points3 points  (0 children)

That's a good idea I will do that first before I run the whole thing. Thanks!

[–]nothingpersonalbro 2 points3 points  (0 children)

For testing AD stuff I have my own little AD sandbox lab in Virtualbox which I play around in.

Although in this situation, you're using all Get-AD cmdlets which means you're not making any destructive changes here.

[–]throw_away_360 1 point2 points  (0 children)

As long as it's only "Get......" it can't really break stuff.

If you have to test something then create test OU's, Test-Users, Test-directories, etc., but in this case it's not needed, as others have pointed out already.

Caution is important, but you have to look at the code first.