环境变量包和作用域



这个脚本应该创建一些新的驱动器,但在我运行它后,它们不存在,任何想法为什么?完全卡住了……提前感谢

Function New-Drives {
    Param()
        New-PSDrive -Name AppData -PSProvider FileSystem -Root $env:Appdata
        New-PSDrive -Name Temp -PSProvider FileSystem -Root $env
        $env:TEMP=Join-Path -Path C:WindowsTemp
        $mydocs=Join-Path -Path $env:userprofile -ChildPath Documents
        New-PSDrive -Name Docs -PSProvider FileSystem -Root $mydocs
}
DIR temp: | measure-object –property length -sum
New-Drives

您需要将-Persist参数添加到New-PSDrive调用中。否则它只会在powershell会话中创建驱动器。

最新更新