header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Script to detect WebDAV and it's status
Last Post 22 May 2009 05:57 AM by halr9000. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Alex AlborzfardUser is Offline
New Member
New Member
Posts:61
Avatar

--
21 May 2009 06:34 AM
    I have a script that pieced together from various sources that only checks for existence of IIS process, but I can't get it to work. (see attached)
    Is it possible to detect WebDAV installation for IIS and it's status (enabled or disabled) on a box using PS?
    If so, perhaps could someone give me some pointers on how to modify my script to do this?

    TIA

    ProcessesMonitoring_IIS.ps1

    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    21 May 2009 07:07 AM
    One authoritative way which will work with all webdav servers is to check the HTTP headers using the OPTIONS HTTP verb.
    PS C:\> $url = 'http://test.webdav.org/dav/' PS C:\> $xhttp = New-Object -ComObject msxml2.xmlhttp PS C:\> $xhttp.open("OPTIONS", $url, $false) PS C:\> $xhttp.send() PS C:\> $xhttp.getAllResponseHeaders() Date: Thu, 21 May 2009 15:00:36 GMT Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.3.2 DAV: 1,2 DAV: MS-Author-Via: DAV Allow: OPTIONS,MKCOL,PUT,LOCK Content-Length: 0 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/plain PS C:\> $xhttp.getResponseHeader("DAV") 1,2
    If that very last statement returns anything, then you are good.


    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    Alex AlborzfardUser is Offline
    New Member
    New Member
    Posts:61
    Avatar

    --
    21 May 2009 07:16 AM
    Thanks Hal. Pardon my ignorance, but I'm completely lost here! Do I put these commands in a PS script or run it from a command prompt? One thing I forgot to mention is that I'd need to run it against all Windows servers on our network. So if it's the latter, it would be very tedious.

    Could you also take a look at the script I had attached and let me know what I'm doing wrong?

    Thanks again


    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    21 May 2009 07:44 AM
    Ok, anything you can do at a prompt you can put in a script and it works the same. My code was more of an example than the code you would need for your script, though.

    Insert this <a href="http://poshcode.org/1120">Test-WebDAV function</a> into your script, just like you did with Send-Mail. Then, later in the script, call it like this (example code, you'll have to figure out what valid URLs are in your case)

    foreach ($Url in $MyListOfUrls) { if( test-webdav -url $url ) { DoStuffHere } else { ItBrokeDoSomethingElse } }


    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    Alex AlborzfardUser is Offline
    New Member
    New Member
    Posts:61
    Avatar

    --
    21 May 2009 08:43 AM
    Thanks again. I put that in the script and ran it, but I'm still getting the same error "list is required!"...
    (see attached)

    Check_WebDAV_on_IIS.ps1

    Alex AlborzfardUser is Offline
    New Member
    New Member
    Posts:61
    Avatar

    --
    22 May 2009 05:41 AM
    Any ideas as to how this can be resolved? (besides giving up on PS scripting!)


    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    22 May 2009 05:57 AM
    Oh, definitely don't give up, you are just getting started! I do think you may want to step back a little and analyze what is going on. The list required error is due to you not specifying a required parameter to the very first bit of code in the attached script. It would probably benefit you to start over. This script is fine--but if you don't understand it you are going to get a headache every time you have to touch it and that's not good.

    So, stepping back. The one and only goal of your NEW script is to detect webdav. Forget about email for now, or IIS process detection.

    As I stated before, you'll need to know webdav URLs that are valid for your site. You already have server names or IPs in a file, right? It should be a matter of tacking on just a bit of text.

    Do these steps at a PROMPT. Trust me, play in the prompt and you'll come to a better understanding of the objects you are tossing around. Do a single logical operation at a time and go slow. Set things to temporary variables, and then inspect them with Get-Member and other methods. For example (you don't need to type the comments, the part starting with #):

    $a = get-content serverlist.txt
    $a | get-member # show properties and methods
    $a | select -first 10 # displays first 10 lines of file
    $a.length # now you know the number of lines in the file
    $a[0] # displays first line
    $a[-1] # last line
    $a[0].ToUpper() # capitalizes a string

    Now make the URLs...

    $url = $a | foreach-object { "http://$_/MySitePath" }
    $url # check out your new handiwork

    Now test them using that function I showed you earlier. Just type it in, straight into the prompt. You'll see that PowerShell will continue to prompt you for new lines as long as you have an open script block, showing the ">>" prompt. Here, I go through these steps. I had to clean the results because I didn't have a set of webdav servers handy and each of the lines in the file caused errors. :)

    PS C:\> function Test-WebDav ()
    >> {
    >> param ( $Url = "$( throw 'URL parameter is required.')" )
    >> $xhttp = New-Object -ComObject msxml2.xmlhttp
    >> $xhttp.open("OPTIONS", $url, $false)
    >> $xhttp.send()
    >> if ( $xhttp.getResponseHeader("DAV") ) { $true }
    >> else { $false }
    >> }
    >>
    PS C:\> $url = $a | ForEach-Object { "http://$_/path" }
    PS C:\> $url
    http://one/path
    http://two/path
    http://three/path
    PS C:\> $url | ForEach-Object { Test-WebDav $_ }
    False
    False
    False



    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer