PS: Startup Script

1 minute read

Description:

One of my main goals this year is to replace all of my batch scripts with Powershell scripts. These are some examples.

To Resolve:

  1. When calling external programs, there is really one a few rules:

    • Use & to call the app.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    #Shut down VMs
    
    Try
    {
       Write-Output "Gracefully shutting down VMs so we can reboot"
       # Website
       & "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" controlvm "XXXXXXX-383a-00000-bb2f-6da0ea34f94c" acpipowerbutton
       # Plex
       & "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" controlvm "XXXXXXX-2816-00000-bd90-7af3cf0b39cb" acpipowerbutton
    }
    Catch
    {
       Write-Error -Message $($_.Exception.Message)
    }
    
    • And my startup script:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    #Startup
    
    Write-Output "Running default startup script"
                   
    # Start-Process "Z:\google\myexe.exe"
    # Start-Process "Z:\google\myexe.exe"
    # Placed in "shell:startup" instead...
                
    Set-Location "C:\Program Files\Oracle\VirtualBox"
    & vdesk create:3
    
    $Command = 'C:\Program Files (x86)\VDesk\vdesk.exe'
    $Arguments = @("on:3", "run:$Arguments2")
    $Arguments2 = '"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "gw-www" --startvm "XXXXXXX-383a-4121-bb2f-6da0ea34f94c"'
    & $Command $Arguments
    
    $Command = 'C:\Program Files (x86)\VDesk\vdesk.exe'
    $Arguments = @("on:3", "run:$Arguments2")
    $Arguments2 = '"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "gw-plex" --startvm "XXXXXXX-2816-45fa-bd90-7af3cf0b39cb"'
    & $Command $Arguments
    
    Write-Output "Setting BGInfo Background"
    $Command = "C:\Sysinternals Suite\bginfo\bginfo.exe"
    $Arguments = @("C:\bginfo\mysettings.bgi", "/timer:0")
    & $Command $Arguments
    
  2. As mentioned in a previous post, use the Don’t Parse symbol (--%) when converting longer commands.

Comments