当我创建PSDrive时,它通常只是获得它指向的位置的名称。“成为dom-loc-Share(G :)”
New-PSDrive -Description "Group-Drive" –Name "G" –PSProvider FileSystem –Root "\\dom\dfs\dom-loc-Share" –Persist | Out-Null
现在,通过单击名称并将其更改,我将其命名为“ Bob”。但是,我现在创建的每个PSDrive都称为Bob
这很好奇,但不是真正的问题(尽管有人关心解释)。我的问题是:如何在脚本中设置名称,即bob?
我试过
Get-PsDrive G
并检查了属性,但无法在Windows资源管理器中设置显示的名称。
创建PSDrive时,如何将这个名称而不是bob设置为“ Group-Drive”?
如果我尝试Get-WmiObject -Class win32_volume,则会得到以下结果...
我找到了答案,尽管如果有人知道更好的方法,请随时告诉我。
$DNsplit = ((Get-ADUser ([Environment]::UserName)).DistinguishedName).split(",")
$STO = $DNsplit[$DNsplit.count -5].Substring(3,3)
$MyRoot = "\\dom\dfs\dom-$Sto-Share"
$RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2"
if(Test-Path $MyRoot)
{
if(Get-PSDrive | ?{$_.Name -eq "G"})
{
Remove-PSDrive G
}
New-PSDrive –Name G –PSProvider FileSystem –Root $MyRoot –Persist -Scope Global | Out-Null
$a = Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2"
foreach($Key in $a)
{
$CompKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\$($MyRoot.Replace('\','#'))"
if($Key.Name -eq $CompKey)
{
Set-ItemProperty -Path $key.PSPath -Name "_LabelFromReg" -Value "Group-Drive"
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句