我怎样才能使访问了这个功能的函数内创建一个PSDrive来? [英] How can I make a PSDrive created within a function accessible out of this function?

查看:127
本文介绍了我怎样才能使访问了这个功能的函数内创建一个PSDrive来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个函数中的一个新的PS驱动器,使该驱动器只能在该函数内访问。

我如何才能通过调用从主访问的功能,这一职能创造一个PS驱动器?

  $ temproraryPSDriveName =temproraryDrive
 创建-PSDriveBy $ temproraryPSDriveName #private功能简单的创建PSDrive来基于一个逻辑
 DIR $($ temproraryPSDriveName +:)#这个不作为teproraryDrive上班不
                                     #accessible一旦我退出Create-PSDriveBy功能
 

解决方案

给全球范围内为您PSDrive来:

 新-PSDrive来-Name QQ -PSProvider文件系统-root C:\ WINDOWS -Scope全球
 

I assume creating a new PS-Drive within a function makes that drive only accessible within that function.

How can I make a PS-Drive created by calling a function from the MAIN accessible out of that function?

 $temproraryPSDriveName = "temproraryDrive" 
 Create-PSDriveBy $temproraryPSDriveName #private function simply creates PSDrive based on a logic
 dir $($temproraryPSDriveName + ":") #This does not work as the 'teproraryDrive' is not 
                                     #accessible once I exit the Create-PSDriveBy function

解决方案

Give global scope to your PSDRIVE:

New-PSDrive -Name qq -PSProvider filesystem -Root c:\windows -Scope global

这篇关于我怎样才能使访问了这个功能的函数内创建一个PSDrive来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆