PowerShell脚本错误:字符串缺少终止符: [英] PowerShell script error: the string is missing the terminator:

查看:1221
本文介绍了PowerShell脚本错误:字符串缺少终止符:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

极其简单的Powershell脚本...

Incredibly simple powershell script...

#Server side storage copy

$SourceStorageAccount = "myStorageAccount"
$SourceStorageKey = "myKey"

$SourceStorageContext = New-AzureStorageContext –StorageAccountName $SourceStorageAccount -StorageAccountKey $SourceStorageKey

出现错误

在E:\ DeploymentScripts \ Storage \ Test.ps1:6 char:51 + ... geContext – StorageAccountName $ SourceStorageAccount -StorageAccount ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ 缺少终止符:. + CategoryInfo:ParserError:(:) [],ParseException + FullyQualifiedErrorId:TerminatorExpectedAtEndOfString

At E:\DeploymentScripts\Storage\Test.ps1:6 char:51 + ... geContext â€"StorageAccountName $SourceStorageAccount -StorageAccount ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The string is missing the terminator: ". + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

最奇怪的部分是,如果我将ps1文件的内容复制并粘贴到PowerShell命令行中,则可以正常工作!发生了什么事?

The strangest part is if I copy and paste the contents of the ps1 file into a PowerShell command line, it works fine !? What's going on?

显然,我已经删除了我的存储容器名称和密钥,您将需要分配自己的Azure存储帐户名称和api密钥来复制它.

Obviously I have removed my storage container name and key, you will need to assign your own Azure storage account name and api key to replicate it.

在Notepad ++中编辑的脚本的屏幕快照,其中所有字符均可见...

A screen shot of the script edited in Notepad++ with all characters visible...

推荐答案

与该问题类似.

从Web复制cmdlet时,可能会有一些特殊字符.我建议您可以将cmdlet复制到记事本,然后复制到PowerShell.

When you copy cmdlets from Web, maybe there are some special characters. I suggest you could copy the cmdlets to Notepad then copy to PowerShell.

在终端中使用cat filename.ps1很有帮助,您可以看到它确定哪些字符不好,在编辑器中并不明显.

It's helpful to use cat filename.ps1 in the terminal you can see determine which characters are bad, it's not obvious in the editor.

这篇关于PowerShell脚本错误:字符串缺少终止符:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆