Hoping this will be an easy one for somebody, but I just don't have the experience. I'm pulling the mapped network drive info from a PC. I'm testing the path to make sure it's active and that the person still has access. The test works fine. Here's my issue...
If the test is $true, I want it to output a line of code to a new .ps1 file for remapping the drive. I think I'm just about there, but I can't wrap my head around outputting a line of code and not the output of the line. Thanks for any help!
foreach ($Drive IN $Drives)
{
$MND = $Network.OpenSubKey("$Drive")
$Share = $MND.GetValue("RemotePath")
$Path = Test-Path "$Share\*"
IF ($Path -eq $true)
{
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\output.ps1 -append
"New-PSDrive -Name "$Drive" -PSProvider FileSystem -Root "$Share" -Persist"
Stop-Transcript
}
}