Convert PowerShell script to Ansible task

595 views
Skip to first unread message

Rahul Rawat

unread,
Feb 3, 2020, 7:45:02 AM2/3/20
to Ansible Project
Hi,

I have to convert PowerShell Script (using if else condition) into anisble task.
How we can work with condition in ansible tasks.

Here is my powershell script.

        $officeInstalled = Get-WmiObject win32_product | where { $_.Name -like "Microsoft Office*" } | select Name,Version 

if ($officeInstalled -is [array])
{
#
# Office
#

$registryPath="HKLM:\SOFTWARE\Classes\Word.Application\CurVer"
$reg = Get-ItemProperty -Path $registrypath
$Office_version = $reg.'(default)'
$Office_version=$Office_version.substring($Office_version.length - 2, 2)

# Remove Microsoft Office policies (if they exist)
$registryPath=$HKEY+"Software\Policies\Microsoft\Office"
Remove-RegistryKey $registryPath

#
# Office 2016
#

IF ($Office_version -eq "16") {
Write-Host "Office 2016"

#
# Common
#

# Disable 'Welcome to your new Office' dialog
$registryPath=$HKEY+"Software\Microsoft\Office\16.0\FirstRun"
Update-Registry $registryPath "BootedRTM" "1" DWORD
                        }

regards,
Rahul 

Dick Visser

unread,
Feb 3, 2020, 7:58:36 AM2/3/20
to ansible...@googlegroups.com
https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d8ff25b8-d251-4860-9662-8106ffc0d524%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Reply all
Reply to author
Forward
0 new messages