我创建了一个脚本,可以从DropBox复制我们的工作PowerPoint演示模板,并将其保存为默认模板。
某些用户帐户有空格,有些用户帐户没有,我无法获取用于触发此脚本运行的批处理文件。
我已经尝试了我能想到的这一行格式{}""'''等
"'%UserProfile%'\'Dropbox'\'Group Team Folder'\'Templates'\'PowerPoint Template.potx'"
预期的结果是批处理文件使用用户名中的空白" John Smith"作为PowerPoint模板路径的一部分,而不是切断它。
它吐出一个错误,说明路径" C:\ Users \ John"不被承认。
非常感谢任何帮助
@ECHO OFF
If exist "%UserProfile%\Dropbox\Group Team Folder\Templates\PowerPoint Template.potx" (
PowerShell.exe -ExecutionPolicy Bypass -Command "%UserProfile%\Dropbox\Group Team Folder\Templates\Script\Powerpoint Template.ps1"
)
If exist "%UserProfile%\Dropbox (Group)\Group Team Folder\Templates\PowerPoint Template.potx" (
PowerShell.exe -ExecutionPolicy Bypass -Command "%UserProfile%\Dropbox\Group Team Folder\Templates\Script\Powerpoint Template.ps1"
)
PAUSE
如果没有单个刻度,则它不适用于没有空格的用户配置文件的系统。 请注意重复代码的原因是因为在某些系统上Dropbox有2个不同的目录,因此它使用PowerPoint模板来确定路径对于该系统的路径是否正确。
C:\Users\John\Dropbox\Group : The term 'C:\Users\John\Dropbox\Group' is not
recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ C:\Users\John\Dropbox\Group Team Folder\Templates\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
那是我的命令提示错误。
我不知道为什么这不起作用。
答案 0 :(得分:1)
这些是运行PowerShell脚本的常用方法;
使用-File
:
PowerShell.exe -ExecutionPolicy Bypass -File "%UserProfile%\Dropbox\Group Team Folder\Templates\Script\Powerpoint Template.ps1"
使用-Command
:
PowerShell.exe -ExecutionPolicy Bypass -Command "& '%UserProfile%\Dropbox\Group Team Folder\Templates\Script\Powerpoint Template.ps1'"
答案 1 :(得分:0)
我遇到了一些尝试将文件从\复制到其个人资料的用户的问题。
我最终使用了Windows 8.1 $ env变量。
$env:systemDrive\users\$env:USERNAME
但我发现你想在那里运行一个PowerShell脚本,所以Compo会给你提示如何运行它们。