如何找到我的USB闪存驱动器的路径与PowerShell [英] How to find my USB flash drive's path with PowerShell

查看:296
本文介绍了如何找到我的USB闪存驱动器的路径与PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在准备一个ps1文件。它会静默安装一些程序。但我的程序的安装文件保存在我的USB闪存驱动器。在我的ps1文件中,

I am preparing a ps1 file. It will install some programmes silently. But my programmes' setup files were saved in my USB flash drive. In my ps1 file,

cd E:\User\User_Setups

此路径是我的USB闪存驱动器的路径。但它会改变在其他机器。也许G:\,F:\等。
当然,我不想改变这个路径为每个不同的机器。 PowerShell如何通过命令行找到我的USB闪存驱动器的路径?

This path is my USB flash drive's path. But it will change on the other machine. Maybe G:\, F:\ etc. Naturally, I don't want to change this path for every different machines. How PowerShell find my USB flash drive's path by a command-line?

推荐答案

我在我的usb Stick中添加了一个VolumeLabel(MyToolBox),并在profile.ps1中加入以下行:

I added a VolumeLabel("MyToolBox") to my usb Stick and put following line in the profile.ps1:

Get-DriveInfo | % { if( $_.VolumeLabel -eq "MyToolBox"){ Set-Location $_.Name; ./Startup.ps1}}

Get-DriveInfo来自模块Pscx: http://pscx.codeplex.com/
您还需要在您的个人资料中导入...

Get-DriveInfo comes from the module Pscx: http://pscx.codeplex.com/ You need to import this in you profile too...

Startup.ps1脚本位于我的usb棒的根目录中,并在棒上注册了用于会话的别名...

The Startup.ps1 script is in the root of my usb stick and registers aliases on the stick for use in the session...

这篇关于如何找到我的USB闪存驱动器的路径与PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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