Functions/Generic/WebDAVClient.ps1
function Get-AvmWebDavClientInfo { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmWebDavClientInfo .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmWebDavClientInfo .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential ) [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential SoapAction = "urn:dslforum-org:service:X_AVM-DE_WebDAVClient:1#GetInfo" UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/x_webdav" XmlResponse = "GetInfoResponse" } Connect-AvmDevice @SplatParameters } function Set-AvmWebDavClientConfig { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Set-AvmWebDavClientConfig .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Set-AvmWebDavClientConfig .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Byte][System.Boolean]$NewEnable, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewHostURL, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewUsername, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Security.SecureString]$NewPassword, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewMountpointName ) $SecurePointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($NewPassword) $PlainNewPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($SecurePointer) [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($SecurePointer) $avmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:X_AVM-DE_WebDAVClient:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/x_webdav" $AvmWebrequestBody.Action = "SetConfig" $AvmWebrequestBody.InnerBody = @" <s:NewEnable>{0}</s:NewEnable> <s:NewHostURL>{1}</s:NewHostURL> <s:NewUsername>{2}</s:NewUsername> <s:NewPassword>{3}</s:NewPassword> <s:NewMountpointName>{4}</s:NewMountpointName> "@ -f $NewEnable, $NewHostURL, $NewUsername, $PlainNewPassword, $NewMountpointName [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath Body = $AvmWebrequestBody.GenerateBody() XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } |