Questions tagged [new-psdrive]

A PowerShell cmdlet for defining custom drives, which typically map to filesystem locations.

From the docs:

The New-PSDrive cmdlet creates temporary and persistent drives that are mapped to or associated with a location in a data store, such as a network drive, a directory on the local computer, or a registry key, and persistent Windows mapped network drives that are associated with a file system location on a remote computer.

Only persistent drive definitions (-Persist), which are only supported on Windows, are visible to programs outside of PowerShell.

24 questions
11
votes
2 answers

Cannot add "-persist" to New-PSDrive - getting error "network resource type is not correct"

As the title says, if I try to add -persist to the cmdlt, it returns an error: New-PSDrive : The network resource type is not correct At line:1 char:1 + New-PSDrive -Name P -Root ... +…
4
votes
1 answer

How to access a PSDrive from System.IO.File calls?

I'm writing a c# cmdlet which copies files from one location to another (similar to rsync). It even supports ToSession and FromSession. I'd like it to work with PSDrives that use the Filesystem provider but it currently throws an error from…
silicontrip
  • 906
  • 7
  • 23
2
votes
2 answers

What type of object is $: (such as `$code:`) in Powershell?

I was using tab autocompletion for a variable name in Powershell 5.1 today and noticed that one of the choices was the name of a PSDrive. The drive name is docs and I wanted to expand is called $document_name. When I typed $do, the shell did…
chris
  • 588
  • 5
  • 16
1
vote
0 answers

New-PSDrive gives password error from one -Root path, but is fine for another

I have the following script: New-PSDrive -Name X -PSProvider FileSystem -Root "$DeployLocation" -Credential $credentials New-PSDrive -Name K -PSProvider FileSystem -Root "$autobuildSourceFiles" -Credential $credentials When this runs, the first…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
1
vote
0 answers

PowerShell, discover network information (hostnames + IP) and construct network configuration scripts

I would like my Windows Sandbox to automatically find the ip/name of every host on my home network and so automatically populate my C:\Windows\system32\drivers\etc\hosts and create a helpler script that will connect to the shares on those hosts.…
YorSubs
  • 3,194
  • 7
  • 37
  • 60
1
vote
1 answer

New-PSDrive not visible to other shells contrary to MS documentation

I've been trying al sorts of varieties of the following, trying to mount a network share in such a way it can be visible for both other shells and in File Explorer. According to the MS documentation of the related commands, saying one can use…
not2qubit
  • 14,531
  • 8
  • 95
  • 135
1
vote
1 answer

How to enable MAP drive on remote computer session

I've been scratching my head for a long. I've two Windows servers joined to Domain and DFS is installed. So when I'm trying to create a MAP drive remotely from server1 to server2 code is not getting an error and it is showing the drive is created…
1
vote
1 answer

New-PSDrive "The network path was not found"

i have trouble with "New-PSDrive -Root" When i try to map a New-PSDrive -Root $patch with a $path using an array, the cmd does not map the drive but give me an error : "The network Path was not found". The path is working if i use an explorer in my…
su7
  • 66
  • 1
  • 7
1
vote
0 answers

Accessing a remote filesystem with powershell - Issues with PSDrive

I'm trying to automate a process of editing a text file on a remote system every morning. My script: $User = "USER" $File = "C:\secureString.txt" $c = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User,…
Dominick
  • 23
  • 3
1
vote
0 answers

Is it possible to use Compress-Archive using a PSDrive in the -Path and -DestinationPath?

I am using a PSDrive for Compress-Archive but I come across this error: Compress-Archive : The path 'Z:\' either does not exist or is not a valid file system path. At C:\Users\user\somefolder\script.ps1:34 char:5 + Compress-Archive -Path…
japespszx
  • 33
  • 5
0
votes
0 answers

Mount DFS SMB share in remote PS session fails

I'm connecting with PowerShell from my computer to a remote computer (10.44.5.142) and trying to mount a DFS share there (\10.44.5.143\dfs1\share1). It doesn't work correctly - I get error "A specified logon session does not exist. It may already…
simhro
  • 1
  • 1
  • 2
0
votes
0 answers

Why is Get-ChildItem inside a Function Access denied after correct New-PSDrive? (It works outside of the function scope.)

This doesnt work function ImportProcess{ param( [Parameter()] [string]$XMLPath ) $sourcePath = $XMLPath $DestPath = split-path "$sourcePath" -Parent #this gives format without slash at and and makes powerShell…
0
votes
0 answers

PowerShell mounted drive appears not to mount

I have a script where I am attempting to mount a Windows shared drive with PowerShell, and then I want the same script to be able to access this location to create files/folders within the mounted drive and to move files to the mounted drive. The…
Ken
  • 125
  • 1
  • 12
0
votes
1 answer

PowerShell: Copying Items from Network Share to Remote Server while using Credentials

I have files stored on a network share \\domain.company.com\Server01\Folder1\Path that I am looking to perform a recursive copy to a remote server \\RemoteServer1\D$\Temp\Folder1. Initially, I looked at using Copy-Item -Path…
0
votes
2 answers

How to use a variable with New-PSDrive?

I'm writing a small script to map and rename netword drives. I wanted to use variables (user input) in drive letter, but for some reason the script won't accept anything but static drive letters. Please help $button_click_2 = { Remove-PSDrive -Name…
Nawad-sama
  • 151
  • 2
  • 12
1
2