Share via

Powershell命令$PSScriptRoot在win11脚本里不生效?

土豆烧鸡 40 Reputation points
2024-01-19T10:58:38.0633333+00:00

您好: 请教下,谢谢! $PSScriptRoot在win10脚本里生效。 $PSScriptRoot在win11脚本里不生效? 问题一:我要在win11里,用脚本aa.ps1获取这个脚本的路径,请问,应该怎么操作? 问题二:win11提示:在此系统上禁止运 行脚本。是什么原因,可以用脚本处理吗?怎么处理? 问题三:pause在win11的Powershell脚本里不会暂停,怎么处理?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

MotoX80 37,686 Reputation points
2024-01-19T14:06:03.73+00:00

$PSScriptRoot and pause work fine on my Win11 laptop using PS 5.1.

"Running Powershell version {0}" -f $PSVersionTable.PSVersion
""
"Script root is {0}" -f $PSScriptRoot 
""
"Here is the pause function."
get-command pause -ShowCommandInfo
""
"Execution policy is {0}" -f (get-executionpolicy)
""
"Remove whatif to update the execution policy. "
"Powershell needs to opened with 'Run as administrator' to do that."
set-executionpolicy RemoteSigned -whatif
""
"Demonstrate pause."
""
pause

User's image

Was this answer helpful?

1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. 土豆烧鸡 40 Reputation points
    2024-01-23T08:58:01.12+00:00

    User's image

    这个怎么用脚本解决。

    Was this answer helpful?


  2. 土豆烧鸡 40 Reputation points
    2024-01-23T05:53:50.8733333+00:00

    我的环境是: User's image

    User's image

    Was this answer helpful?


  3. 土豆烧鸡 40 Reputation points
    2024-01-23T02:59:01.4833333+00:00

    Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName | Set-Content d:\InstalledSoftwareList.txt这条命令,手工在powershell可生成新文件d:\InstalledSoftwareList.txt。 但是保存成aa.ps1,运行后,不能生成新文件d:\InstalledSoftwareList.txt。 请教,这是什么原因?

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.