O PowerShell não pode criar pasta na montagem de rede

1

Eu criei uma unidade com a letra Z: e a compartilhei para que o caminho da rede seja: \GOELA2682012SRV\srv2012r2

Agora quero criar uma pasta usando o PowerShell.

Isso não funciona: New-Item -Path "\GOELA2682012SRV\srv2012r2\Users\test" -ItemType Directory

Enquanto isso funciona: New-Item -Path "Z:\Users\test" -ItemType Directory

Por quê?

    
por PoTTii 01.05.2016 / 15:48

1 resposta

4

Tente colocar o FileSystem:: no caminho UNC, por isso, torna-se FileSystem::\GOELA2682012SRV\srv2012r2\Users\test

PowerShell’s behavior can be a little bit funny when you pass a UNC path to certain cmdlets. PowerShell doesn’t recognize these paths as “rooted” because they’re not on a PSDrive; as such, whatever provider is associated with PowerShell’s current location will attempt to handle them. For example:

Set-Location C:
Get-ChildItem -Path \$env:COMPUTERNAME\c$

Set-Location HKLM:
Get-ChildItem -Path \$env:COMPUTERNAME\c$

The first command works fine (assuming you have a c$ share enabled and are able to access it), and the second command gives a “Cannot find path” error, because the Registry provider tried to work with the UNC path instead of the FileSystem provider. You can get around this problem by prefixing the UNC path with “FileSystem::”, which will make PowerShell use that provider regardless of your current location.

Gotcha do PowerShell: caminhos e provedores da UNC

    
por 01.05.2016 / 16:08