Condition doesn't seem to work, how to trap this

#Hi Guys,#The If block only works if the server exists, otherwise it gives an exception.With try #catch i got the same problem. My code doesn't continue, the sleep never works.#Even with silent continue i get the exception. #Does anybody knows a good trap logic for AD objectsif (Get-ADComputer $hostName.toUpper()) {
Write "$hostName exists"
AddAd
AddSccmGroup
else {
Write "$hostName does not exists"
start-sleep -s 300
Error:
Get-ADComputer : Cannot find an object with identity: 'Serv9550' under: 'DC=domain,DC=local'.
At D:\scripts\addcomputerad-vco5.ps1:102 char:9
+     if (Get-ADComputer $hostName.toUpper()) {
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (DHGMS9550:ADComputer) [Get-ADCo
   mputer], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'DHGMS9550'
    under: 'DC=anwb,DC=local'.,Microsoft.ActiveDirectory.Management.Commands. 
  GetADComputer
Groetjes André

I'm not sure what AddAd and AddSccmGroup are (I assume they perform some after actions once the machine is in AD), but do you want to call those if the computer has not yet been found in AD?
The quickest approach to a loop would be something like this using a While and keeping it to true and then breaking out of the loop when a computer has been found:
While ($True) {
Try {
if (Get-ADComputer $hostName.ToUpper() -ErrorAction Stop) {
Write "$hostName exists"
AddAd
AddSccmGroup
Break
Catch {
Write-warning "$hostName does not exists"
start-sleep -s 300
It may be worthwhile to have some sort of counter in case the system never shows up to avoid an infinite loop from happening.
$Limit = 15
While ($True) {
$i++
Try {
if (Get-ADComputer $hostName.ToUpper() -ErrorAction Stop) {
Write "$hostName exists"
Break
Catch {
Write-warning "$hostName does not exists"
start-sleep -s 300
If ($i -eq $Limit) {
Write-Warning "$hostname never came up after $limit tries!"
Break
Boe Prox
Blog |
Twitter
PoshWSUS |
PoshPAIG | PoshChat |
PoshEventUI
PowerShell Deep Dives Book

Similar Messages

  • SQL Batch doesn't seem to work; How to eager-fetch related objects?

    Hi,
    I have two technical questions with Kodo.
    1. SQL Batch doesn't seem to work. I have tried batch size of -1, 0, 1, 25.
    But the performance from batch creating objects is not affected by batch
    size.
    kodo.jdbc.DBDictionary: BatchLimit=25
    2. How to use custom fetch groups to eagerly fetch related persistable
    objects? Example only showed attributes, not relationships.
    Enviroment:
    * Kodo 3.1.0 RC1
    * Oracle 9i release 1.
    Qingshan Luo
    Senior Software Engineer
    Open Harbor
    1123 Industrial Road
    San Carlos, CA 94070
    Phone: 650-413-4251
    Fax: 650-413-4298

    try poracle 10g driver. At least they fixed terrible CLOB bug may be batch
    to. BTW 9.2.x has problem with batching with deferred constraints so be
    careful
    "Greg Campbell" <[email protected]> wrote in message
    news:c3dmnu$rmj$[email protected]..
    >
    "Qingshan Luo" <[email protected]> wrote in message
    news:c3dg7q$mdl$[email protected]..
    Hi,
    I have two technical questions with Kodo.
    1. SQL Batch doesn't seem to work. I have tried batch size of -1, 0, 1,25.
    But the performance from batch creating objects is not affected by batch
    size.
    kodo.jdbc.DBDictionary: BatchLimit=25You may be running into a bug in the Oracle 9.2 driver. That driverdoesn't
    reliably give update counts when using batching and prepared statement
    caching. By default, Kodo will turn off batching. You can manuallyenable
    batching by setting the BatchLimit on your DBDictionary, as you've done.If
    you do this, though, you may want to turn off prepared statement cachingby
    setting MaxCachedStatements to 0 (see
    http://www.solarmetric.com/Software/Documentation/3.1.0RC1/docs/ref_guide_dbsetup.html#ref_guide_dbsetup_builtin).
    >
    2. How to use custom fetch groups to eagerly fetch related persistable
    objects? Example only showed attributes, not relationships.You can find information on setting up eager fetching of relations at
    http://www.solarmetric.com/Software/Documentation/3.0.3/docs/ref_guide_
    perfpack_eager.html
    Basically, you'll need to add the relations to your fetch group, and
    set the eager fetching mode.
    Enviroment:
    * Kodo 3.1.0 RC1
    * Oracle 9i release 1.
    Qingshan Luo
    Senior Software Engineer
    Open Harbor
    1123 Industrial Road
    San Carlos, CA 94070
    Phone: 650-413-4251
    Fax: 650-413-4298

  • How do I remove the menu button? The Customize option doesn't seem to work for that.

    How do I remove the menu button? [That IChing looking three line icon on the toolbar.]
    The toolbar Customize option doesn't seem to work, and it seems a waste to have a button that duplicates the menus. I'd like to swap it out for the NoScript icon.

    Hi, ''I can't recommend that you do it'', but If you really are determined, [http://www.tweakguides.com/Firefox_12.html this article] may help.

  • How do you close programs with new iOS7? Old way doesn't seem to work!

    How do you close programs with new iOS7? Old way doesn't seem to work!

    After double tap home button, swipe up on the app card that appears above the icon.

  • How to reset the iPad - the Location Services doesn't seem to work?

    How to reset the iPad - the Location Services doesn't seem to work?
    I can not get NFL Game Pass or Siri to work???

    Well you can plug it into itunes and under summary tab hit RESTORE. This should fix any software issues that you may be experiencing. About gamepass, I dont know, I dont have it. Siri is not on the IPAD2. Only on the 3rd generation Ipad, so you wont have it(going by ipad2 under your name).

  • How do you reset/repair javascripts? Enabling doesn't seem to work

    When I enter various websites, they list an advisory message that I must enable javascripts in order to use their sites. When I enable javascripts from the contents section from tools in firefox, it doesn't seem to work. How can I reset or repair the javascripts function in the firefox program to allow me to access and use various websites?

    The website you mentioned http://www.arbitersports.com is opening fine (see attached screenshot) without any error messages or warnings on my Win Xp & Firefox 9.0.1..
    -> [[JavaScript]]
    * http://kb.mozillazine.org/JavaScript
    -> [[Using the Java plugin with Firefox]]
    -> Perform the suggestions mentioned in the following articles:
    * [https://support.mozilla.com/en-US/kb/Template:clearCookiesCache/ Clear Cookies & Cache]
    * [[How to clear the cache#w_clear-the-cache|Clear the Network Cache]]
    * [[Troubleshooting extensions and themes]]
    Check and tell if its working.
    -> Update Firefox to the latest version (9.0.1)
    * [[Updating Firefox]]
    -> Update All your Firefox Plugins
    * https://www.mozilla.org/en-US/plugincheck/
    * '''When Downloading Plugins Update setup files, Remove Checkmark from Downloading other Optional Softwares with your Plugins (e.g. Toolbars, McAfee, Google Chrome, etc.)'''
    * Restart Firefox

  • Hi, I have photoshop CC. It's the french version but I would like to have it in english. I went in the creative cloud to change the language but it doesn't seem to work. Do you know how i could do it ?

    Hi, I have photoshop CC. It's the french version but I would like to have it in english. I went in the creative cloud to change the language but it doesn't seem to work. Do you know how i could do it ?

    Please indicate whether or not the following link helps... I have not had to use it and so I do not know if/when it does help.
    Creative Cloud Help / Adjust the install language | Creative Cloud applications | CCM -
    http://helpx.adobe.com/creative-cloud/kb/change-installed-language.html

  • HT1296 How can I transfer a ringtone from my iPad to my iPhone? Syncing doesn't seem to work.

    How can I transfer a ringtone from my iPad to my iPhone? Syncing doesn't seem to work.

    See this discussion: https://discussions.apple.com/message/22514325#22514325

  • I would like to cancel my subscription for Adobe ExportPDF Subscription that I have just signed up for as it doesn't seem to work with my system. How do I do this ?many thanks suslucie

    I would like to cancel my subscription for Adobe ExportPDF Subscription that I have just signed up for as it doesn't seem to work with my system. How do I do this ?many thanks suslucie

    Hi Susan,
    I checked using the email you provided, and there's no history of any orders under that email address. (Then, I removed your email address from you post, since this is a public forum and it's best not to broadcast contact information.)
    I'll message you privately, and you can send along your email from Adobe if you'd like.
    Best,
    Sara

  • How to reflect db changes - Verify Database doesn't seem to work

    I have changed a database (MS SQL Server) column from varchar 255 to varchar 1000, but the designer doesn't pick up the change.
    I read that db changes can be picked up by using 'Verify Database' feature. It doesn't seem to work for us though. Is there any configuration to turn on for the feature to work properly or any work-around to refresh the database changes?
    We are making the database connection using JDBC (JNDI) option since the report is being used in a Java web application.
    Any comments or insights will be very much appreciated!

    Hi Wallie,
    Thank you very much for your reply! Here are the answers to your questions.
    Are you able to create a new report off the modified database?
    ==> Yes.
    Do new reports see the changes made to the database?
    ==> No.
    Are the reports connecting directly to the database table, or is it a stored procedure, business view, universe being used?
    ==> Through a business view.
    By the way, after trying so many things, I was able to figure out the reason. Since the report is using a view, not directly the table, the view itself had to be recompiled to reflect the table changes so that the view could pass the changes to the report. It was a very good thing to know. Your last question could have been a very helpful insight for this issue! Thank you so much again!

  • How do I delete a "consecutive group" of emails? Shift click doesn't seem to work.

    upgrades computer to win 7 and from outlook express to thunderbird. 500 emails in inbox. outlook express allowed me to select the first email and then shift click the last email in a group of emails to be deleted all at the same time. thunderbird doesn't seem to allow me to do this. or am I doing something wrong. I don't want to sit for hours deleting 500 emails one at a time.
    thank you

    You're doing something wrong. Thunderbird works the same way.

  • Safari on my iPhone 6 running 8.02 doesn't seem to work right. Some Java scripts don't show correctly and they do on other browsers I have downloaded. I tried almost everything and nothing seems to work to fix it. Please help.

    Some websites like the one of my college uses JavaScripts and they seem to load correctly to a certain point but then not really. For example in one it would say select an option from the left menu. And I do it hut nothing happens. But when I go to the same website in another browser on my phone. The JavaScript works completely and allows me to see whatever I was clickig on that menu. I have seen that there are other websites being affected too. I tried clearing my cookies and data. even restarted my phone. And doesn't seem to work. I don't know how change the configuration any more to make it work like normal. At first I thought it was my school's website but it never got fixed. And now I realized is my safari browser! I wanna keep using it since I am really familiar with It. If someone knows how to fix this please let me know!
    Thanks

    You can reset the SMC and see if that helps. If it's a unibody or Retina, follow the method for "a battery you should not remove yourself."
    http://support.apple.com/kb/ht3964

  • Pdfmark code in MS Word 2008 doc doesn't seem to work properly to create Named Destination

    Hi all,
    I've been having trouble with creating Preview-compatible Named Destinations in Acrobat 9.x (see http://forums.adobe.com/thread/770470?tstart=0).  Distiller, on the other hand, appears to create compatible Destinations, so as a last-ditch effort, I tried to go back to my original source file (Microsoft Word 2008 document) to use Distiller's pdfmark functionality, to see if maybe I could finally get a PDF with Preview-compatible Destinations.
    Following instructions found elsewhere on this forum, I went into Word and inserted the following field into a test location in my document:
    PRINT "[ /Dest /testdest /View [ /XYZ null null null ] /DEST pdfmark"
    This field code is supposed to then cause a pdfmark to be inserted into the resulting PostScript and/or PDF files.  Distiller is supposed to understand this and turn it into a Named Destination called "testdest."  However, it doesn't seem to work - I don't see the pdfmark code in the PS file, and the PDF file doesn't have any Named Destinations in it.
    I'm using Acrobat 9.x on Mac OS X 10.6.5, so I tried this two different ways:
    1) Using the "Print to Adobe PDF" workflow (which replaced the "Adobe PDF Printer" from previous OS/Acrobat versions) - this automatically generates a PDF via (presumably) an API call to Distiller... and
    2) Using the "Print to Postscript" workflow to generate a PS file, which I then ran through Adobe Distiller.
    In neither case did I end up with a named destination in the PDF file, as I was supposed to.  In case #2, even the Postscript file didn't have a pdfmark embedded in it.  Thus, I'm assuming that perhaps this is particular issue may be a problem with MS Word 2008 rather than with Acrobat... but I'm hoping someone might have a clue as to how to fix it.
    I welcome ideas on how to get Word 2008 to properly output pdfmark code, so that Distiller will pick it up and properly embed a Named Destination into the PDF...
    Thanks in advance.
    (If anyone has ideas about the Preview-compatible problem, linked above, that would also be great!)

    You're suggesting that it was never fixed from Word 2004 to 2008?  Possibly.  I wonder if it's fixed in Word 2011?  Anyone know?  But is it really a Word problem, rather than a Distiller issue?
    I appreciate your offer, though I do have access to Word on Windows (2003, I think), so I could try Distilling there... I only worry about formatting, since there are minor differences (e.g. font kerning, etc.) between Mac and Windows that are subtle, but sufficient to create formatting issues for very long documents (e.g. pushing figures onto the wrong pages, etc.).  That would be a rather big problem.
    The question remains whether this is an issue with Word or Distiller, though... and whether it's fixed in Distiller X and/or Word 2011.
    Adobe, care to comment?
    I'd really love to find a proper Mac solution, if one exists... it would be rather a slap to Mac users if a solution doesn't exist.

  • I want pictures from each device in the cloud, but not on every other device. Possible? "iCloud Backup" alone doesn't seem to work....

    My goal is to acheive 3 of the following things.:
    Have all my apple devices sync pictures to the icloud *without* syncing the pictures on all the devices...so just one direction from device to cloud and not have all the devices insync from the cloud...... I don't want all the devices in sync, I just want the pictures protected in the cloud. To do this, I've tried to just turn on "icloud bacn-up" and not turn on "photo stream" to acheive this, but doesn't seem to work.
    If #1 is possible, then I would like to sync the icloud with a folder on my PC using the icloud app for the PC. Not sure if I can have only the icloud PC sync and not have all the devices in sync?
    If #1 and #2 could work, then I would sync the PC folder with my local storge.
    end result would be all my photos save in the cloud and a safe copy my home in my local storage. I would have thought that most people would want to do this, but doens't seem so obvious to me as to how I can get it to work?
    Any help would be appreicated.
    thanks

    You can't use iCloud as a safe place to store your photos when they are deleted from your devices.  iCloud designed to stream photos to your devices, and to back up photos currently on your your devices as part of your iCloud backups.  However, photo stream photos only remain in iCloud for 30 days, giving your devices enough time to download them.  And if you delete a photo stream photo from any of your devices, it is also deleted from iCloud and from all of your devices.  Furthermore, while camera roll photos are included in your backup, if you then delete the photos from your device and continue backing up, the backup containing the deleted photos will be overwritten by one that doesn't, and they will be lost.
    If you want to save your photos, import them from the camera roll to your computer as explained here: http://support.apple.com/kb/HT4083.  Then you can delete them from your device.
    If you would rather have a cloud-based place to store your photos, look into a service such as Dropbox.

  • SetDocument doesn't seem to work correctly

    I'm obviously using the setDocument method for my JTextField incorrectly, but how? The DocumentSizeFilter works correctly, allowing only the number of characters I specify, but the DigitDocument.insertString(...) doesn't seem to work at all (it should allow for only digits to be entered into the JTextField).
              AbstractDocument doc;
              pafTextField = new JTextField();
              pafTextField.setDocument(new DigitDocument());
              pafTextField.setPreferredSize(new Dimension(30, height));
              doc = (AbstractDocument)pafTextField.getDocument();
              doc.setDocumentFilter(new DocumentSizeFilter(2));The DigitDocument class:
    public class DigitDocument extends PlainDocument{
         public DigitDocument(){
              super();
         public void insertString(int offs, String str, AttributeSet a) throws BadLocationException, NumberFormatException{
              try{
                   System.out.println("String str = " + str);
                   int i = Integer.parseInt(str);
                   super.insertString(offs, str, a);
              catch(NumberFormatException e){
                   // do nothing because a user input was not a digit
                   Toolkit.getDefaultToolkit().beep();
    }the DocumentSizeFilter code:
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/DocumentSizeFilter.java

    didn't try the abstract doc, but why not combine the two
    something like this
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    class Testing extends JFrame
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JTextField tf = new JTextField(new DigitDocument(2),"",10);
        JPanel p = new JPanel();
        p.add(tf);
        getContentPane().add(p);
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    class DigitDocument extends PlainDocument{
      int maxChars;
      public DigitDocument(int chars){
        super();
        maxChars = chars;
      public void insertString(int offs, String str, AttributeSet a) throws BadLocationException, NumberFormatException{
        try{
          System.out.println("String str = " + str);
          if(this.getLength()+str.length() > maxChars) throw new NumberFormatException();//<----
          int i = Integer.parseInt(str);
          super.insertString(offs, str, a);
        catch(NumberFormatException e){
          // do nothing because a user input was not a digit
          Toolkit.getDefaultToolkit().beep();
    }

Maybe you are looking for

  • Animated GIF is running to fast

    I have an animated GIF in my Java app, and it seems to be running really fast for some reason. When the GIF is just placed in an HTML page to view it runs at the normal speed. Any help? Thanks.

  • Cannot open an idml file created in CS5.5 in either CS5 or CS5.5

    I have exported a CS5.5 file to idml but I cannot get it to open in either CS5 or CS5.5. Below is a screenshot of the error I get in both versions. I have tried getting rid of all 3rd party plugins and resetting preferences to ID defaults in both CS

  • Making Contact Form Work?

    Greetings, I have set up a contact form on one of my web pages that consists of Name, Email and Comments with a Submit button. I am wondering how I can get it to actually work! I've done some online research but have come up empty handed. Any help on

  • Html code for table...

    In the numbers discussion group it would be really helpful if we had a way to use html tables to demonstrate our advice. not anything fancy just basic <table> codes would be helpful. Does anyone know the discussion group equivalent to this? I can't s

  • Registry settings used by iTunes drivers for importing and burning CDs

    I'm using Windows 7, started getting this error message "The registry settings used by the iTunes drivers for importing and burning CDs and DVDs are missing. This can happen as a result of installing other CD burning software. Please reinstall iTunes