【发布时间】:2018-06-25 14:52:44
【问题描述】:
我有一个脚本正在尝试针对 Azure 订阅运行。该脚本抓取已发布的配置文件设置,例如用户名、密码和 url,以 FTP 文件到该目录。我直接从 Microsoft 文档中获取了语法,该文档概述了如何执行此操作。请参阅此链接以使用带有空输出文件的 xml:Msft.Doc
很遗憾,我收到一条错误消息:
方法调用失败,因为 [System.String] 不包含名为“SelectNodes”的方法。
我不确定为什么会这样。谢谢!
$appdirectory="<app directory>"
$webappname="<webapp name>" ##"mywebapp$(Get-Random)"
$location="East US"
$ResourceGroupName="<resource group name>"
# Get publishing profile for the web app
$xml = (Get-AzureRmWebAppPublishingProfile -Name $webappname `
-ResourceGroupName $ResourceGroupName `
-OutputFile null)
# Extracts connection information from publishing profile
$username = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userName").value
$password = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userPWD").value
$url = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@publishUrl").value
#ftp test 2
$request = [Net.WebRequest]::Create("$url")
$request.Credentials = New-Object System.Net.NetworkCredential("$username", "$password")
$request.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
# make sure to create the path or change the URL to file.
$fileStream = [System.IO.File]::OpenRead("C:\tmp\test.txt")
$ftpStream = $request.GetRequestStream()
$buffer = New-Object Byte[] 10240
while (($read = $fileStream.Read($buffer, 0, $buffer.Length)) -gt 0)
{
$ftpStream.Write($buffer, 0, $read)
$pct = ($fileStream.Position / $fileStream.Length)
Write-Progress `
-Activity "Uploading" -Status ("{0:P0} complete:" -f $pct) `
-PercentComplete ($pct * 100)
}
$fileStream.CopyTo($ftpStream)
$ftpStream.Dispose()
$fileStream.Dispose()
我知道有一个类似的问题,但它略有不同,因为我正在遵循 Microsoft 文档给出的示例,其中输出文件在我的情况下为空。
【问题讨论】:
-
-OutputFile null看起来不正确? -
@JamesC。请参阅已编辑的问题以及官方文档,使用带有 -OutPutFile null 的确切示例,没有明确的 .xml 文件。谢谢!
标签: powershell azure azure-powershell