重启后Powershell功能不工作?



我的功能在重启前工作正常,但之后不行。为什么?

代码:

Function import-cloud {
Robocopy "C:Userssonde2021sky" "C:UserssondeSkrivebord2021lokal" /MIR
}
Function export-cloud { 
Robocopy "C:UserssondeSkrivebord2021lokal" "C:Userssonde2021sky" /MIR
}

输入图片描述

在Powershell启动过程中没有正常加载cmdlet或Functions。

在开始:

  1. Powershell从$env:PSModulePath目录加载模块的描述符,以便在您尝试从其中一个模块使用CmdLet时准备内部调用import-module。这被称为自动加载,它有点棘手,所以只有模块供应商使用这个。

  2. 如果存在,Powershell执行$Profile文件。如果您在这里定义了任何东西,它将被执行。如果您在这里定义函数,它将被执行(对于函数这意味着存储在RAM中并准备使用)


作为最简单的方法,您应该创建一个$profile文件并将这些函数粘贴在这里:

[void][System.IO.Directory]::CreateDirectory([System.IO.Path]::GetDirectoryName($profile))
If (-not [System.IO.File]::Exists($profile)) { '' | Out-File $profile }
Start-Process -Verb 'Edit' -FilePath $profile

最新更新