Posts

Showing posts with the label foreach

How to iterate through an array list of classes

How to iterate through an array list of classes import java.util.ArrayList; public class circleTester { public static void showCenter(Circle2 circle) { System.out.println(circle.getName() + "'s " + circle.getCenter()); } public static void main (String args) { ArrayList<Circle2> circles = new ArrayList<Circle2>(); circles.add(new Circle2(3, 5, 4)); circles.add(new Circle2(4, 2, 5)); circles.add(new Cylinder2(5, 2, 3, 5)); circles.add(new Cylinder2(3, 4, 7, 6)); circles.add(new Oval2(6, 5, 7, 3)); circles.add(new Oval2(4, 2, 3, 1)); circles.add(new OvalCylinder2(2, 3, 4, 5, 6)); circles.add(new OvalCylinder2(3, 3, 5, 4, 7)); for (Circle2 i : circles) { showCenter(circles(i)); } } } I have four separate classes: Circle2, Cylinder2, Oval2, and OvalCylinder2. They're all derived from Circle2, and OvalCylinder2. I'm t...

Skip part of script on error

Skip part of script on error I've been banging my head against the wall for awhile on this one. No amount of Googling has yielded me any successful results thus far. Wondering if someone can give me a hand? # Load the PowerShell module for Active Directory Import-Module ActiveDirectory # For each computer in AD that is a member of the target group Get-ADGroupMember -Identity "CN=RenameComputer,CN=Users,DC=int,DC=example,DC=com" | ForEach { # Define the new name as the old one, minus one letter at the end $NewComputerName = $_.Name -replace ".$" # Perform the rename operation Rename-Computer -ComputerName $_.Name -NewName $NewComputerName -Force -PassThru -Restart -WhatIf # Remove the computer from the target group # THIS SHOULD NOT OCCUR IF THE RENAME ABOVE FAILED!!! Remove-ADGroupMember -Identity "CN=RenameComputer,CN=Users,DC=int,DC=example,DC=com" -Members $NewComputerName -WhatIf } TL;DR: Thi...