Functions/Connect-NAS01.ps1
function Connect-NAS01 { [CmdletBinding()] param ( [Parameter()] [string] $DriveLetter = "M" ) $DeviceName = "NAS01" $TestConnect = Test-NetConnection $DeviceName if ($TestConnect.PingSucceeded -eq $false) { $TestConnect = Test-NetConnection 192.168.178.150 $DeviceName = "192.168.178.150" } 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 \\192.168.178.150\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 } } |