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
You can use the Persist parameter of New-PSDrive to create Windows mapped network drives. Unlike temporary PowerShell drives, Windows mapped network drives aren't session-specific. They're saved in Windows and they can be managed by using standard Windows tools, such as File Explorer and net use.
If you're using PowerShell to work with a file system, registry, certificates, or even network drives, you've got to check out PowerShell drives. PowerShell drives or PS drives are a concept in PowerShell that allows you to work with structured data like a file system. The New PSDrive cmdlet is the way to begin.
A Windows PowerShell drive is a data store location that you can access like a file system drive in Windows PowerShell.
The Remove-PSDrive cmdlet deletes temporary PowerShell drives that were created by using the New-PSDrive cmdlet. Beginning in Windows PowerShell 3.0, Remove-PSDrive also disconnects mapped network drives, including, but not limited to, drives created by using the Persist parameter of New-PSDrive .
Give global scope to your PSDRIVE:
New-PSDrive -Name qq -PSProvider filesystem -Root c:\windows -Scope global
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With