Milestone 9 ‐ dc‐blue1, blue.local - ryanm292002/SEC480 GitHub Wiki

9.1

image

image

There are multiple things that need to be changed so I used parameters which essentially allowed me to use the strings from running the function ref:https://www.techtarget.com/searchwindowsserver/tip/Understanding-the-parameters-of-Windows-PowerShell-functions

function changewinip {
    #define input parameters for the function, these are the string values that will be provided when running the function
    param (
        [Parameter(Mandatory=$true)]
        [string]
        $vm,
        
        [Parameter(Mandatory=$true)]
        [string]
        $ipaddr,

        [Parameter(Mandatory=$true)]
        [string]
        $subnetmask,

        [Parameter(Mandatory=$true)]
        [string]
        $defaultgateway,

        [Parameter(Mandatory=$true)]
        [string]
        $DNSnameserver,

        [Parameter(Mandatory=$true)]
        [string]
        $ethernetdevice

    )
  1. Try, catch statement (catch=error handling) with using invoke-vmscript to utilize netsh to change the IP, DNS, Gateway, Subnet mask. The DNS is seperate from the rest as it requires different command.
        $InvokeIP = Invoke-VMScript -VM $targetVm -GuestCredential $cred -ScriptText "netsh interface ipv4 set address name='$ethernetname' static $ip $mask $gateway " 
 $InvokeDNS = Invoke-VMScript -VM $targetVm -GuestCredential $cred -ScriptText "netsh interface ipv4 add dns name='$ethernetname' $nameserver index=1"

  1. Full function can be found inside the 480utils.psm1, function is called "changewinip"

9.2

  1. Install the windows collection which allows ansible to function with Windows devices.

ansible-galaxy collection install ansible.windows

  1. Running the ansible script through powershell, normally Id use winrm but powershell was what came up first during my research and seemed to work great.