Announcement

Collapse
No announcement yet.

Powershell script to launch 'OSFMount'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powershell script to launch 'OSFMount'

    I made a Powershell script to launch 'OSFMount' at the start of Windows.
    Works for Windows 10 Home 20H2

    OSFMount.ps1 :

    Start-Process "D:\Documents\OSFMount\osfmount.com" -ArgumentList "-a -t vm -m E: -o logical,rw,format:exfat:RamDisk -s 8G" -NoNewWindow -Wait
    New-Item -Path "E:\Temp" -ItemType Directory

    Task_OSFMount.ps1 :

    $Principal = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent())
    If (-Not ($Principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
    Write-Warning "You do not have Administrator rights to run this script. Please run PowerShell as an Administrator."
    Break
    }
    $taskName = "OSFMount"
    $TaskScript = "D:\Documents\OSFMount\OSFMount.ps1"
    $TaskArgument = "-ExecutionPolicy Bypass -File $TaskScript"
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -ne $null) { Unregister-ScheduledTask -TaskName $taskName -Confirm:$false }
    $action = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Argument $TaskArgument
    $trigger = New-ScheduledTaskTrigger -AtStartup
    $settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -Priority 1 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit '00:00:00'
    $principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
    $definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings -Description "Run $($taskName) at startup"
    Register-ScheduledTask -TaskName $taskName -InputObject $definition
    Read-Host -Prompt 'Press any key to continue...'
    Last edited by QQQQ; Feb-11-2021, 04:22 AM.
Working...
X