Functions/Connect-NAS01.ps1


function Connect-NAS01 {
    [CmdletBinding()]
    param (
        [Parameter()] [string] $DriveLetter = "M"
    )

    $DeviceName = "NAS01"

    $TestConnect = Test-NetConnection $DeviceName

    if ($TestConnect.PingSucceeded -eq $true) {

        mount.exe -o anon \\$DeviceName\i-data\ea12954a\nfs\Shared M:

        $AppPath = "powershell.exe"
        $TaskName = "Launch $AppPath"
        $Argument = '-NoProfile -command "mount.exe -o anon \\NAS01\i-data\ea12954a\nfs\Shared M:"'
        $action = New-ScheduledTaskAction -Execute $AppPath -Argument $Argument
        $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date)
        Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $TaskName | Out-Null
        Start-ScheduledTask -TaskName $TaskName

        Start-Sleep -s 3
        Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false


    } else {

        # Write-Error "NAS01 not online"
        break

    }


}