Jump to content


Photo

Add - remove domains with powershell


  • Please log in to reply
3 replies to this topic

#1 Richard Robinson

Richard Robinson
  • Members
  • 0 posts

Posted 01 July 2010 - 04:25 AM

Hello everybody,Has anyone written a powershell script that uses Barracuda 4.1 API to Add/Remove domains and play around with domain settings? I've read lots of info on xml-rpc but I am not a developper. Just an admin looking for some detailed script exemples.Thanks for your help!

#2 Richard Robinson

Richard Robinson
  • Members
  • 0 posts

Posted 01 September 2010 - 04:22 AM

Here's a working exemple of domain.add in powershell. Enjoy:clear-host$reqURL = "http://CUDAIP:8000/cgi-mod/api.cgi?password=apipassword"$reqXml = @"<?xml version="1.0" encoding="UTF8"?><methodCall><methodName>domain.add</methodName><params><param><value><struct><member><name>domain</name><value><string><![CDATA[domain.com]]></string></value></member></struct></value></param></params></methodCall>"@$reqXml $content = [Text.Encoding]::UTF8.GetBytes($reqXml)$httpReq = [Net.HttpWebRequest]::Create($reqURL)$httpReq.Method = "POST"$httpReq.UserAgent = ""$httpReq.ContentType = "text/xml"$httpReq.ContentLength = $content.Length$reqStream = $httpReq.GetRequestStream()$reqStream.Write($content, 0, $content.Length)$reqStream.Close()$httpRes = $httpReq.GetResponse()if($httpRes.StatusCode -ne "OK") { Write-Error "The problem occurred while acquiring the response." exit 1}$resStream = $httpRes.GetResponseStream()$resXml = [xml]((New-Object IO.StreamReader($resStream)).ReadToEnd())$resStream.Close()#$ResXml$resXml.methodResponse.get_innertext()write-host "-----"$resXml.methodResponse.InnerXml$response = $resXml.methodResponse.params.param.value.get_innertext()$response = ">" + $response + "<"write-host $response

#3 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 01 September 2010 - 08:28 AM

In a wWindows environment, use VB script.http://forum.barracuda.com/bb/viewtopic.php?t=14556Check out my second post, it's an ASP example, just remove the Server. from the Server.CreateObject.My first post has the xml strings to post.

#4 Richard Robinson

Richard Robinson
  • Members
  • 0 posts

Posted 02 September 2010 - 02:45 AM

And here's hwo to set domain variables - always in powershell:$reqURL = "http://CUDAIP:8000/cgi-mod/api.cgi?password=apipassword"$reqXml = @"<?xml version="1.0" encoding="UTF8"?><methodCall><methodName>config.set</methodName><params><param><value><struct><member><name>scana_pd_tag_level</name><value><i4>1.2</i4></value></member><member><name>scana_pd_quarantine_level</name><value><i4>10</i4></value></member><member><name>scana_pd_block_level</name><value><double>4.7</double></value></member><member><name>mta_relay_advanced_host</name><value><string><![CDATA[mail1.domain.com,mail2.domain.com]]></string></value></member><member><name>scana_pd_spam_scan</name><value><string><![CDATA[Yes]]></string></value></member><member><name>scana_pd_virus_scan</name><value><string><![CDATA[Yes]]></string></value></member><member><name>scana_pd_pu_quarantine</name><value><string><![CDATA[Yes]]></string></value></member><member><name>path</name><value><string><![CDATA[domain.com]]></string></value></member><member><name>type</name><value><string><![CDATA[domain]]></string></value></member></struct></value></param></params></methodCall>"@$reqXml $content = [Text.Encoding]::UTF8.GetBytes($reqXml)$httpReq = [Net.HttpWebRequest]::Create($reqURL)$httpReq.Method = "POST"$httpReq.UserAgent = ""$httpReq.ContentType = "text/xml"$httpReq.ContentLength = $content.Length$reqStream = $httpReq.GetRequestStream()$reqStream.Write($content, 0, $content.Length)$reqStream.Close()$httpRes = $httpReq.GetResponse()if($httpRes.StatusCode -ne "OK") { Write-Error "The problem occurred while acquiring the response." exit 1}$resStream = $httpRes.GetResponseStream()$resXml = [xml]((New-Object IO.StreamReader($resStream)).ReadToEnd())$resStream.Close()#$ResXml$resXml.methodResponse.get_innertext()write-host "-----"$resXml.methodResponse.InnerXml$response = $resXml.methodResponse.params.param.value.get_innertext()$response = ">" + $response + "<"write-host $response