save-date:# Name of the class and the modulecmd.run:- name:date.exe /T > C:\tmp\my-date.txt- cwd:C:\tmp#- user: breathbath ##Use it only as root- shell:cmd.exe- env:- PASSWORD:bunny- creates:C:\tmp\my-date.txt# Don't execute if file exists.remove-date:cmd.run:- name:del C:\tmp\my-date.txt- shell:cmd.exe- require:- save-date- onlyif:date.exe /T | findstr -i "^Thu"# Execute only on Thursdays
# Installs/updates VNC Server and either licenses it offline with license key # or joins to the cloud with a cloud connectivity token# CONFIGURE PARAMETERS BELOW TO YOUR REQUIREMENTS# Set version of VNC Server to install, e.g. 7.1.0# Defaults to Latest{{$Version := "Latest"}}# Set if we're using cloud or offline# Accepted values: offline, cloud{{$CloudOrOffline := "cloud"}}# Set offline license to apply# Not required if joining to the cloud{{$OfflineLicense := ""}}# Set cloud connectivity token to join VNC Server to the cloud# Not required if using direct connections only{{$CloudToken := ""}}# Set group to join VNC Server to - group must exist in the VNC Connect portal# Optional{{$CloudGroup := ""}}# DO NOT EDIT BELOW THIS LINE{{$WindowsScriptPath := "C:\\Windows\\Temp\\vnc.ps1"}}template:file.managed:- name:{{$WindowsScriptPath }}- contents:| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Version = "{{ $Version }}"
$CloudOrOffline = "{{ $CloudOrOffline }}"
$OfflineLicense = "{{ $OfflineLicense }}"
$CloudToken = "{{ $CloudToken }}"
$CloudGroup = "{{ $CloudGroup }}"
# Use TEMP for downloaded files
$TempPath = $env:TEMP
# Detect architecture
$Architecture = "64bit"
if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -ne "64-bit"){
$Architecture = "32bit"
}
# Download MSI archive from RealVNC website
Invoke-WebRequest -URI "https://downloads.realvnc.com/download/file/vnc.files/VNC-Server-$Version-Windows-msi.zip" -OutFile "$TempPath/VNC_MSIs.zip"# Unzip downloaded archive - this requires Powershell 5Expand-Archive "$TempPath/VNC_MSIs.zip" -DestinationPath "$TempPath/VNC_MSIs" -Force# Cleanup downloaded archive now that it's been extractedRemove-Item -Path "$TempPath\VNC_MSIs.zip"# Select MSI matching OS architecture$MSIFilename = Get-ChildItem "$TempPath\VNC_MSIs\*$Architecture*.msi" | Select-Object -ExpandProperty Name# Install VNC Server MSI silentlyStart-Process msiexec.exe -Wait -ArgumentList "/I $TempPath\VNC_MSIs\$MSIFilename /qn"# Cleanup MSIsRemove-Item -Path "$TempPath\VNC_MSIs" -Recurse# Determine if we are licensing by key or cloud joiningif ($CloudOrOffline -eq "offline"){# Call vnclicense.exe to apply the keyStart-Process "C:\Program Files\RealVNC\VNC Server\vnclicense.exe" -Wait -ArgumentList "-add $OfflineLicense"}elseif ($CloudOrOffline -eq "cloud"){if ((& 'C:\Program Files\RealVNC\VNC Server\vncserver.exe' -service -cloudstatus | ConvertFrom-JSON | Select-Object -ExpandProperty CloudJoined) -eq $false){# If CloudGroup is set, use it to join VNC Server to that group - group must exist in the VNC Connect portalif ($CloudGroup -ne ""){$joinGroup = "-joinGroup $CloudGroup"# Call vncserver.exe to do the cloud joinStart-Process "C:\Program Files\RealVNC\VNC Server\vncserver.exe" -Wait -ArgumentList "-service -joinCloud $CloudToken $joinGroup"}else{Start-Process "C:\Program Files\RealVNC\VNC Server\vncserver.exe" -Wait -ArgumentList "-service -joinCloud $CloudToken"}}}- skip_verify:true- mode:0755- encoding:UTF-8cmd.run:- names:- PowerShell.exe -ExecutionPolicy Bypass -File {{ $WindowsScriptPath }}- DEL {{ $WindowsScriptPath }}- shell:cmd.exe