<powershell>

$recipe_key = "chef/app-voicehost-1519160624.tar.gz"

Get-DnsClient | Set-DnsClientServerAddress -ServerAddress("<%= dns_servers.join(',')  %>")

Set-DnsClientGlobalSetting -SuffixSearchList @("curse.io")
Get-DnsClient | Set-DnsClient -ConnectionSpecificSuffix "curse.io"

echo "cookbook_path '/chef/cache/cookbooks'" | Out-File c:\chef\solo.rb -Encoding UTF8

mkdir /chef/cache
Set-ExecutionPolicy RemoteSigned -Force
Copy-S3Object -BucketName twitchapp-deploys-useast1-8af373d7d186efd2afc096138fc67ba92ef24 -Key $recipe_key -LocalFile c:\chef\cache\app-voicehost.tar.gz -Region us-east-1
cd /chef/cache
Start-Process C:\opscode\chef\bin\tar.exe "xvzf app-voicehost.tar.gz" -Wait
cd c:\

chef-solo -o app-voicehost::windows-firewall
chef-solo -o app-voicehost::finish-host

rm /chef/cache -recurse

echo <%= host_type || 1 %> > "C:\Program Files\CurseVoice\CurseVoiceMode.txt"

$instanceid = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id

$id = $instanceid.Substring(2, 9)

$host_name = get-content env:computername

if (!($host_name.ToLower() -eq "video-$id")) {
  Rename-Computer -NewName "video-$id" -Force -Restart
}

</powershell>
