Powershell to click on 'ok' to delete an SP site

72 Views Asked by At

I am trying to create a script to delete old MOSS 2007 personal sites. I have most of the script working, but where I am having trouble is once a box pops up, to have it click 'Ok'. The script locates the URL, and clicks on 'delete', but then a box pops to confirm deletion and the options are 'Ok' and 'cancel'. I want the script to click on 'ok'. I've done some research on the sendkey methods, but since I'm not well versed in PS, I'm unable to get it to work. Also, please don't suggest using the SP cmds. We have MOSS 2007 running on 2003 servers, so any SP cmds or trying to run the script from the server is a moot point. Please take a look at my script below.

[void] 
[System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[void] 
[System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")

$user = "username"

 $mysiteURL = "http://SharePointSite/personal/$user/_layouts/deleteweb.aspx"



 Invoke-WebRequest -UseDefaultCredentials -uri $mysiteURL  | Select-Object statusdescription


#Creates an Internet Explorer object
    $ie = New-Object -ComObject 'internetExplorer.Application'

    $ie.Visible= $true
    $ie.Navigate($mysiteURL) 

    while ($ie.Busy -eq $true){Start-Sleep 4;}

    $ie.Document.getElementByID('ctl00_PlaceHolderMain_ctl08_RptControls_BtnDelete').click()

#give the focus to ie
[Microsoft.VisualBasic.Interaction]::AppActivate("Message from webpage")

 #send keys 
 start-sleep 1
  [System.Windows.Forms.SendKeys]::Sendwait("{ENTER}");

Any help would be appreciated. Thank you!

0

There are 0 best solutions below