Friday, January 21, 2011

Move Active Directory Group to Another OU using Powershell

How do I move an active directory group to another organizational unit using Powershell?

ie.

I would like to move the group "IT Department" from:

  (CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca)

to:

  (CN=IT Department, OU=Temporarily Moved Groups, DC=Company,DC=ca)
  • I haven't tried this yet, but this should do it..

    $objectlocation= 'CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca'
    $newlocation = 'OU=Temporarily Moved Groups, DC=Company,DC=ca'
    
    $from = new-object System.DirectoryServices.DirectoryEntry("LDAP://$objectLocation")
    $to = new-object System.DirectoryServices.DirectoryEntry("LDAP://$newlocation")
    $from.MoveTo($newlocation,$from.name)
    
  • Hi Steven. Your script was really close to correct (and I really appreciate your response).

    The following script is what I used to solve my problem.:

    $from = [ADSI]"LDAP://CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca"
    $to = [ADSI]"LDAP://OU=Temporarily Moved Groups, DC=Company,DC=ca"
    $from.PSBase.MoveTo($to,"cn="+$from.name)
    
    Steven Murawski : Great!! Thanks for posting the update!
    From Eldila

CausesValidation is set to "False" but the client side validation is still firing

I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on the client side when I press the Cancel button, which has the CausesValidation attribute set to "False". How can I get this to stop?

I do not believe that Validation Groups are supported in 1.1.

Here's a code sample:

<asp:TextBox id="UsernameTextBox" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="UsernameTextBoxRequiredfieldvalidator" ControlToValidate="UsernameTextBox" 
runat="server" ErrorMessage="This field is required."></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="UsernameTextBoxRegExValidator" runat="server" ControlToValidate="UsernameTextBox"
Display="Dynamic" ErrorMessage="Please specify a valid username (6 to 32 alphanumeric characters)." 
ValidationExpression="[0-9,a-z,A-Z, ]{6,32}"></asp:RegularExpressionValidator>

<asp:Button CssClass="btn" id="addUserButton" runat="server" Text="Add User"></asp:Button>
<asp:Button CssClass="btn" id="cancelButton" runat="server" Text="Cancel" CausesValidation="False"></asp:Button>

Update: There was some dynamic page generating going on in the code behind that must have been messing it up, because when I cleaned that up it started working. Thanks everyone.

Thanks Mark

  • Are they in separate validation groups (the button and validator controls)?

    You're not manually calling the JS to do the client validation are you?

    From Slace
  • Without seeing your code (or at least a piece of it) no answer will be 100%. edit: thanks for the code sample!

    From Chuck
  • Validation Groups were not added to ASP.NET until version 2.0. This is a 1.1 question.

    Double check your setting and make sure you are not overwriting it in the code behind.

    From dbugger

Whats the best windows tool for merging RSS Feeds?

Hi all,

It seems like such a simple thing, but I can't find any obvious solutions...

I want to be able to take two or three feeds, and then merge then in to a single rss feed, to be published internally on our network.

Is there a simple tool out there that will do this? Free or commercial..

update: Should have mentioned, looking for a windows application that will run as a scheduled service on a server.

  • Maybe http://www.planetplanet.org/ will do what you want.

    It's for creating blog aggregations like planet lisp.

    emk : Planet Planet is very nice if you want to turn the RSS feeds into a single website. It can be set up in 20 minutes or so once you have Python installed.
  • Google reader, create a group, add your feeds into the folder and then share that as an RSS feed.

    :-)

    Works while you're asleep!

    From Ben
  • There are a whole pile of options here: http://allrss.com/rssremixers.html.

  • Yahoo Pipes could be nice. Depends on how much "private" you want the resulting feed to be.

    For 100% offline solution investigate Atomisator. It's a Python framework basically for doing offline what Yahoo Pipes does online.

    From phjr
  • If you're using PHP, the SimplePie library will do this. Here's a tutorial.

    From ceejayoz

Which library should I use to generate RSS in Common Lisp?

What's the best library to use to generate RSS for a webserver written in Common Lisp?

  • xml-emitter says it has an RSS 2.0 emitter built in.

  • CL-WHO can generate XML pretty easily.

  • I am not aware of any specific RSS library. But the format is fairly simple so any library that can write xml will do at that level.

    You could have e.g. a look at the nuclblog (http://cyrusharmon.org/projects?project=nuclblog) project as that has the capability to generate an RSS feed for the blog entries it maintains.

    From HD
  • Most anything will probably do. Personally, I've been using xml-emitter for my blog's Atom feed, which has worked out well so far.

    Just choose whichever XML generation library you like and hack away, I'd say. As others have remarked, RSS is simple; it's little work to generate it manually.

    That said, I recommend not generating plain strings directly. Having to deal with quoting data is more of a hassle than installing an XML library, and it's also insecure in case your feed contains data submitted by visitors of your website.

Simple third party Captcha I can add to my website.

Just something simple like showing an image and asking the user to type in the number on the image.

  • Take a look at reCAPTCHA. It's free, easy to add and helps a good cause (digitizing books). It's also accessible to the blind or visually impaired.

    Clay Nichols : Yes, saw reCaptcha & looks promising but it's 2+ words. My users are non-techie so I'd like to keep it simple ("12") & blocks 95% of the spam. Gatekiller's solution seems the best for Javascript enabled options meeting my criteria. http://beta.stackoverflow.com/questions/8472?sor
    From dF
  • I'm sure there are other questions on this site regarding this, but CAPTCHA, in its current conceptualization, is broken and often easily bypassed. NONE of the existing solutions will block 95% of spam - GMail succeeds only 20% of the time, at best.

    It's actually probably a lot worse than that, since that statistic is only using OCR, and there are other ways around it. I recently gave a talk on the subject at OWASP, but the ppt is not online yet...

    While CAPTCHA cannot provide actual protection in any form, it may be enough for your needs, if what you want is to block casual drive-by trash. But it won't stop even semi-professional spammers.

    From AviD
  • If you dont want to use third party capcha you can create your own its simple in PHP you can see more details here http://www.white-hat-web-design.co.uk/articles/php-captcha.php

how to save a public html page with all media and preserve structure

Looking for a linux application (or firefox extension) that will allow me to scrape an html mockup and keep the page's integrity. Firefox does an almost perfect job but doesn't grab images referenced in the css.

The Scrabbook extension for Firefox gets everything, but flattens the directory structure.

I wouldn't terribly mind if all folders became children of the index page.

  • Have you tried wget?

  • Teleport Pro is great for this sort of thing. You can point it at complete websites and it will download a copy locally maintaining directory structure, and replacing absolute links with relative ones as necessary. You can also specify whether you want content from other third-party websites linked to from the original site.

    From X-Cubed
  • See Website Mirroring With wget

    wget --mirror –w 2 –p --HTML-extension –-convert-links http://www.yourdomain.com
    
    From Gilean
  • wget -r does what you want, and if not, there are plenty of flags to configure it. See man wget.

    Another option is curl, which is even more powerful. See http://curl.haxx.se/.

    From Thomas
  • /palmface, i didn't even consider checking the man for wget/curl.

    wget, though those options should do it all, doesn't seem to be working for me. have to toy with the command line.

    From Adam

Publishing vs Copying

What is the difference between publishing a website with visual studio and just copying the files over to the server? Is the only difference that the publish files are pre-compiled?

  • I believe you are correct in your assumption. It has been my experience that the only difference is that published files are compiled. Visual Studio® 2008 Web Deployment Projects is a nice enhancement for customizing your build scripts for both your Websites and Web Applications.

  • There is not much difference between "publish", and copying the files. Publish appears in a webapplication. The only difference really is publishing gives you the option to only include html and dll's, where as copying you would need to parse out source code manually. There is no full precompiling in the publish option, as Fully precompiled means no HTML at all; The aspx files are just placeholders; All html is in the compiled binaries.

    From mattlant

Which is the best book to learn and understand XQuery?

Which is the best book to learn and understand XQuery for a beginner like me? Please note, I understand other XML technologies.

It would be really good if the book gives reasoning behind decisions. Strengths and weaknesses of XQuery. When to use and when not to use XQuery?

  • I like "XQuery" from O'Reilly.

    Another good one is "XQuery: The XML Query Language"

    From aku
  • I have XQuery from the Experts, but I'm not sure if it is easy reading. I think XQuery is pretty complicated so there might not be an easy read on the subject.

    From Bryant
  • The folks at W3Schools have some pretty good tutorials and resources for a variety of web technologies, you may want to start with their XQuery tutorial. That may give you a better understanding with which to evaluate what book suites your needs and learning style.

    From Joe Skora

What do you call the tags in Subversion and CVS that add automatic content?

Things like $log$ and $version$ which add data upon check-in to the file. I'm interested in seeing the other ones and what information they can provide, but I can't get much info unless I know what they are called. Thanks.

Is there a working on-the-fly compilation in NetBeans 6.5 and how well is it doing?

I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java files. This feature is well known from Eclipse: Simply store the file and the compiled class is stored, too. Is NetBeans working the same way? If not, how is it ticking?

How do you detect and print the current drilldown in the CrystalReportViewer control?

When using Business Objects' CrystalReportViewer control, how can you detect and manually print the report the user has currently drilled into? You can print this automatically using the Print() method of the CrystalReportViewer, but I want to be able to do a manual printing of this report.

It is possible to print the main ReportSource of the CrystalReportViewer, but I need to know what report the user has drilled into and then do a manual printing of that particular drill down. Any ideas?

  • I'm not sure which version of Crystal Reports you are using, but if it is XIR2 or earlier then this isn't possible. I haven't used the newer versions so I can't tell you. One thing that I've done to solve this in the past was to have the drill actually link to another report altogether. It depends on how your viewers actually view the reports (either via a thick-client viewer, the developer, or the web portal) on whether this will work however. Good luck!

How do I get my Disciplines to appear in published Site (in EPF Composer 1.5)?

I have a custom category ("disciplines") in my method plugin which I want to use to contain existing disciplines (from the Scrum plugin and EPF OpenUP library) as well as a few of my own (some are new, and others extend the OpenUP ones). I can add them simply, order them as desired, and view them in the Browsing Perspective and Preview tab.

However, when I publish, I cannot see the disciplines I have added or extended. There are no errors in the publish logs and the warnings I have refer to other things.

  • Your custom disciplines and extensions must contain tasks. When you add some, they will be visible upon publishing.

How do I set the HttpOnly flag on cookie in rails

The page http://www.codinghorror.com/blog/archives/001167.html explains why making HttpOnly cookies is a good idea

How do I set this property in RubyOnRails

  • Just set :http_only to true as described in the changelog.

  • Set the 'http_only' option in the hash used to set a cookie

    e.g.

    cookies["user_name"] = { :value => "david", :http_only => true }

  • I also wrote a patch that is included in Rails 2.2, which defaults the CookieStore session to be http_only.

    Unfortunately session cookies are still by default regular cookies.

    From Pelle

DataSet.Select and DateTime

How can I use .NET DataSet.Select method to search records that match a DateTime? What format should I use to enter my dates in?

  • The best method is dd MMM yyyy (ie 15 Sep 2008). This means there is no possiblity of getting it wrong for different Locals.

    ds.select(DBDate = '15 Sep 2008')
    

    You can use the DateFormat function to convert to long date format as well and this will work fine too.

    From Leo Moore
  • I use the following for the SQL Select:

        public string BuildSQL()
        {
            // Format: CAST('2000-05-08 12:35:29' AS datetime)
            StringBuilder sb = new StringBuilder("CAST('");
    
            sb.Append(_dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.Append("' AS datetime)");
    
            return sb.ToString();
        }
    
    From creohornet

How to save code snippets (vb/c#/.net/sql) to sql server

I want to create a code/knowledge base where I can save my vb.net/c#.net/sqlserver code snippets for use later.

I've tried setting the ValidateRequest property to false in my page directive, and encoding the value with HttpUtility.HtmlEncode (c#.net), but I still get errors.

thoughts?

why might my pyglet vertex lists and batches be very slow on Windows?

I'm writing opengl code in python using the library pyglet. When I draw to the screen using pyglet.graphics.vertex_list or pyglet.graphics.batch objects, they are very slow (~0.1 fps) compared to plain old pyglet.graphics.draw() or just glVertex() calls, which are about 40fps for the same geometry. In Linux the vertex_list is about the same speed as glVertex, which is disappointing, and batch methods are about twice as fast, which is a little better but not as much gain as I was hoping for.

  • I don't know personally, but I noticed that you haven't posted to the pyglet mailing list about this. More Pyglet users, as well as the primary developer, read that list.

  • Don't forget to invoke your pyglet scripts with 'python -O myscript.py', the '-O' flag can make a huge performance difference.

    From Tartley

google maps providing directions in local language

I noticed that google maps is providing directions in my local language (hungarian) when I am using google chrome, but english language directions when I am using it from ie. I would like to know how chrome figures this out and how can I write code that is always returning directions on the user's language.

  • I could be way off but I think it's fairly safe to assume that google, is using gears.

    From Unkwntech
  • HTTP requests include an Accept-Language header which is set according to your locale preferences on most OS/browser combinations. Google uses a combination of that, the local domain you use (eg 'google.it', 'google.hu') and any preferences you set with the Preferences link in the home page to assign a language to your pages.

    It's likely that IE is misrepresenting your locale to Google Maps, whereas Chrome has correctly guessed it. You can change IE's locale by changing your national settings in Control Panel, while Chrome's locale can be changed in (wrench menu) > Preferences.

    From millenomi

MVC validation, will it conflict with other JS frameworks?

Hi,

If I want to use the validation framework that you can use with ASP.NET MVC, will the javascript conflict with other javascript frameworks like jquery or YUI?

  • There are many MVC frameworks. There are many JavaScript frameworks that have different functionalities. If you want a meaningful answer, you should choose an MVC and a JavaScript framework and ask concerning those two. Please be as detailed as possible in your questions.

    As an example, the validation handling on ActiveRecord (used in Ruby on Rails) only performs validations on the server end. You can always add JavaScript validations on top of that, but the server-side validations are what really matters for data integrity.

    Ben Scheirman : he did specify ASP.NET MVC
  • No, it will not. Currently, ASP.NET MVC doesn't have an inherent validation framework. So you are free to use any server/client-side validation framework you wish.

    From Haacked
  • I'm pretty sure Haacked is talking about the ASP.NET MVC Validation shown here:
    ScottGu's Blog - ASP.NET MVC Preview 5 and Form Posting Scenarios

    If this is the case, then the answer is: Yes you can use JQuery in conjunction with this.
    Multiple Comments on the linked page talk about using JQuery for Ajax.

    From KyleLanser

leaving a time delay in python

is there any way to leave a time delay between the execution of two lines of code?

  • You can use the sleep() function in the time module. It can take a float argument for sub second resolution.

    from time import sleep
    sleep(0.1) # Time in seconds.
    
    AlberT : is it completely cross plat or there is any kind of issue on Win, for example, I'd have to care about? Thank you in advance.
    From pobk

Can I submit a Struts form that references POJO (i.e. not just String or boolean) fields?

I have a Struts (1.3x) ActionForm that has several String and boolean properties/fields, but also has some POJO fields.

so my form looks something like:

MyForm extends ActionForm {
    private String name;
    private int id;
    private Thing thing;

    ...getters/setters...
}

In the JSP I can reference the POJO's fields thusly:

<html:text property="thing.thingName" />

...and the values display correctly, but if I try to submit the form I get the ServletException: BeanUtils.populate error.

There seems to be a lot of information about this general topic on the web, but none really addresses my specific question, which is: shouldn't I be able to submit a form in Struts that contains fields that are POJOs?

  • You can, as long as the fields follow the JavaBean conventions and the setter takes something Struts can understand.

    So Thing needs getThingName() and setThingName(String).

How do you reliably get an IP address via DHCP?

I work with embedded Linux systems that sometimes want to get their IP address from a DHCP server. The DHCP Client client we use (dhcpcd) has limited retry logic. If our device starts up without any DHCP server available and times out, dhcpcd will exit and the device will never get an IP address until it's rebooted with a DHCP server visible/connected. I can't be the only one that has this problem. The problem doesn't even seem to be specific to embedded systems (though it's worse there). How do you handle this? Is there a more robust client available?

  • The reference dhclient from the ISC should run forever in the default configuration, and it should acquire a lease later if it doesn't get one at startup.

    I am using the out of the box dhcp client on FreeBSD, which is derived from OpenBSD's and based on the ISC's dhclient, and this is the out of the box behavior.

    See http://www.isc.org/index.pl?/sw/dhcp/

  • You have several options:

    1. While you don't have an IP address, restart dhcpcd to get more retries.
    2. Have a backup static IP address. This was quite successful in the embedded devices I've made.
    3. Use auto-IP as a backup. Windows does this.
    benc : This is a good answer. The asker should remember that having the DHCP client broadcast forever could be bad behavior in some environments.
  • Add to rc.local a check to see if an IP has been obtained. If no setup an 'at' job in the near future to attempt again. Continue scheduling 'at' jobs until an IP is obtained.

    From jpbarto

Detect DOM modification in Internet Explorer

I am writing a Browser Helper Object for ie7, and I need to detect DOM modification (i.e. via AJAX). So far I couldn't find any feasible solution.

How to Convert ISO 8601 Duration to TimeSpan in VB.Net?

Is there a standard library method that converts a string that has duration in the standard ISO 8601 Duration (also used in XSD for its duration type) format into the .NET TimeSpan object?

For example, P0DT1H0M0S which represents a duration of one hour, is converted into New TimeSpan(0,1,0,0,0).

A Reverse converter does exist which works as follows: Xml.XmlConvert.ToString(New TimeSpan(0,1,0,0,0)) The above expression will return P0DT1H0M0S.

Flexible compiler pipeline definitions...

I'm developing a compiler framework for .NET and want a flexible way of defining pipelines. I've considered the following options:

  • WWF
  • Custom XML pipeline description
  • Custom pipeline description in code (using Nemerle's macros to define syntax for it)
  • Other code-based description

Requirements:

  • Must not depend on functionality only in the later versions of .NET (3+) since it's intended to be cross-platform and be used on top of managed kernels, meaning semi-limited .NET functionality.
  • Must allow conditional pipeline building, so you can specify that certain command line options will correspond to certain elements and orders.

WWF would be nice, but doesn't meet the first requirement. The others would work but are less than optimal due to the work involved.

Does anyone know of a solution that will meet these goals with little to no modification?

  • If you know Ruby then a solution is to write a simple internal DSL that can generate whatever pipeline data types and reader/writer code you need. Generating XML is a quick way to get started. You can always change the DSL to generate another format later if required.

    You may also want to look at the Microsoft Phoenix compiler project for inspiration.

    Cody Brocious : This is similar to the use of Nemerle macros to define syntax for such pipelines, except that the macros would translate everything at compile-time. It's a nice solution from a usability standpoint, but it requires a lot of work to put it together.
    From MB
  • I know Boo let you have fun with the compiler, not sure if it does in the manner you want.

    From pmlarocque

Sum of items in a collection

Using LINQ to SQL, I have an Order class with a collection of OrderDetails. The Order Details has a property called LineTotal which gets Qnty x ItemPrice.

I know how to do a new LINQ query of the database to find the order total, but as I already have the collection of OrderDetails from the DB, is there a simple method to return the sum of the LineTotal directly from the collection?

I'd like to add the order total as a property of my Order class. I imagine I could loop through the collection and calculate the sum with a for each Order.OrderDetail, but I'm guessing there is a better way.

  • You can do LINQ to Objects and the use LINQ to calculate the totals:

    decimal sumLineTotal = (from od in orderdetailscollection
    select od.LineTotal).Sum();
    

    You can also use lambda-expressions to do this, which is a bit "cleaner".

    decimal sumLineTotal = orderdetailscollection.Sum(od => od.LineTotal);
    

    You can then hook this up to your Order-class like this if you want:

    Public Partial Class Order {
      ...
      Public Decimal LineTotal {
        get {
          return orderdetailscollection.Sum(od => od.LineTotal);
        }
      }
    }
    
    aku : Arghh! You outran me this time. Anyway +1 vote.
    Omer van Kloeten : note that the order class should be partial, since it's already been generated by the LINQ to SQL generator.
    Espo : aku: Finally, thanks for the vote :) Omer: Thank you, i will update the code
    From Espo

Loading Assemblies from the Network

This is related to the this question and the answer maybe the same but I'll ask anyways.

I understand that we can start managed executables from the network from .NET 3.5 SP1 but what about assemblies loaded from inside the executable? Does the same thing apply?

  • My understanding is yes, you're trying to load an untrusted module into your local app domain.

    From Dan Blair
  • You have been able to load Assemblies from the network at leasst from .NET 2.0. I have used this on a previous project. The only thing to watch is the size of the assembly and the number and size of the dependancies that it is loading.

    If you are using a seperate AppDomain, then you will need to take special consideration of the dependancies.

    From MrHinsh

Overlapped I/O on anonymous pipe

Is it possible to use overlapped I/O with an anonymous pipe? CreatePipe() does not have any way of specifying FILE_FLAG_OVERLAPPED, so I assume ReadFile() will block, even if I supply an OVERLAPPED-structure.

  • No. As explained here, anonymous pipes do not support asynchronous I/O. You need to use a named pipe. There's example code to do this on MSDN here and here.

    From ChrisN
  • Here is an implementation for an anonymous pipe function with the possibility to specify FILE_FLAG_OVERLAPPED. If the link should die in the future search the net for MyCreatePipeEx.

    Steve Hanov : Thanks! That's just what I needed.

Whats the best way to do throbber in C#?

Specifically what I am looking to do is make the icons for the Nodes in my System.Windows.Forms.TreeView control to throb while a long loading operation is taking place.

  • If you load each frame into an ImageList, you can use a loop to update to each frame. Example:

        bool runThrobber = true;
        private void AnimateThrobber(TreeNode animatedNode)
        {
            BackgroundWorker bg = new BackgroundWorker();
            bg.DoWork += new DoWorkEventHandler(delegate
            {
                while (runThrobber)
                {
                    this.Invoke((MethodInvoker)delegate
                    {
                        animatedNode.SelectedImageIndex++;
                        if (animatedNode.SelectedImageIndex >= imageList1.Images.Count) > animatedNode.SelectedImageIndex = 0;
                    });
                    Thread.Sleep(100);
                }
            });
            bg.RunWorkerAsync();
        }
    

    Obviously there's more than a few ways to implement this, but here's the basic idea.

    Factor Mystic : Looking at this again, you should really check and see if the image index is in the bounds of the imagelist.images count before you increment it.

Debugging with FF3 in VS2008

I am using Firefox 3 to debug my ASP.NET applications in Visual Studio 2008. How can I configure either FF3 or VS2008 so that when I 'x' out of Firefox I don't have to hit the stop debugging button in Visual Studio? (The behavior you get with IE)

  • The same question applies to Safari and Chrome.

  • I have the same thing. I assume you're working with Cassini (the integrated web server).

    I've yet to find an answer to that (I just go back to VS and press Shift+F5 to stop the debugger), but I can tell you that if you check the "Edit and Continue" box in the project's properties (web tab), your web server will stop and restart whenever you run your application.

    It doesn't solve the whole of the problem, but it suffices for me.

  • My solution to this has been to manually attach the debugger to the relevant browser and the aspnet_wp process. When I'm finished, I simply detach all.

    From Raithlin
  • Extending upon Raithlin's suggestion, Ctrl+Alt+P is a useful shortcut to bring up the Attach to Process window.

    From Kon