diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..768b0cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Project specific objects # +########################### +Tests/TestVars + + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/Media/lab-config-example.jpg b/Media/lab-config-example.jpg new file mode 100644 index 0000000..0593fb0 Binary files /dev/null and b/Media/lab-config-example.jpg differ diff --git a/Modules/PSWindowsUpdate.zip b/Modules/PSWindowsUpdate.zip deleted file mode 100644 index 91b0378..0000000 Binary files a/Modules/PSWindowsUpdate.zip and /dev/null differ diff --git a/README.md b/README.md index f33040f..e662db9 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,49 @@ Lab Config ====================== -A collection of simple scripts that run against a vSphere environment to enforce consistency and enables self-healing on a regular basis. The premise is that you'd want to fill out a vars file with your standards, and then let the script engine run hourly / nightly / weekly to control drift and absorb new assets that are brought online. - -## Description -Pretty straight forward. The engine's job is to start up a job for each script. Each script parses the vars file to determine what variables and options you want enforced. -- Set standards for a lab environment (which is what I do) and use a pull or utility server to run the engine on a schedule. -- Pick apart the scripts to use with other orchestration engines, or just as ideas for your code. - -## Installation -Copy or fork the repo into your environment. Make sure you have PowerShell 4.0+ installed, along with PowerCLI 5.8+. The scripts are not signed, so you'll need to adjust your PowerShell ExecutionPolicy based on where you're running the engine file. - -## Usage Instructions -Here's the scoop. - -1. Update the vars.ps1 file with your domain specific information. -2. Decide how you wish to run the scripts: - 2. Option 1: Run the engine.ps1 file, which will call all of the scripts in the various folders. - 3. Option 2: If you don't want to run all of the scripts, open up the engine.ps1 file and edit the $jobMap variable and remove references to the scripts you wish to remove. - 4. Option 3: Just ignore the engine.ps1 file and run the scripts individually. They will still use the vars.ps1 file and have some limited output to the console. - -Here's an example of what the $jobMap var looks like: -``` -$jobMap = [Ordered]@{ - "DNS" = "\VMware\set-dns.ps1"; - "NTP" = "\VMware\set-ntp.ps1"; - "SSH" = "\VMware\set-ssh.ps1" -} -``` - -## Future -This is mainly a lab helper for Wahl Network, but I figured the code examples might be interesting to folks, or others with home labs might want to take advantage of the scripts. -- Microsoft scripts - - DNS for clients - - Network RSS settings - - WinRM control -- More 3rd party stuff - - PernixData is on my radar - - NSX perhaps? - -## Contribution -Create a fork of the project into your own reposity. Make all your necessary changes and create a pull request with a description on what was added or removed and details explaining the changes in lines of code. If approved, project owners will merge it. - -Licensing ---------- -Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +This is a community project that aims to provide an extremely light-weight approach to vSphere configuration management using Pester and PowerCLI. Each component monitored is both tested and remediated against drift. The end-state configuration is abstracted into a simple config file. The entire project is written in PowerShell. + +# Requirements + +You'll just need a few free pieces of software. + +1. PowerShell version 4+ +2. [PowerCLI version 5.8+](http://www.vmware.com/go/powercli) +5. [Pester](https://github.com/pester/Pester) +4. (optional) [Windows Management Framework 5.0](https://www.microsoft.com/en-us/download/details.aspx?id=50395) + +# Installation + +Download the files contained within this project anywhere you want. You can even make different copies for different environments. + +# Usage Instructions + +1. Edit the `Config.ps1` file with your specific environmental variables for DRS, NTP, SSH, etc. +1. Open a PowerShell console. +2. Navigate to the project folder that you downloaded. +3. Run `Invoke-Pester` to launch the tests. + +![Example](/Media/lab-config-example.jpg?raw=true "Example") + +# Future -Support -------- -Please file bugs and issues at the Github issues page. The code and documentation are released with no warranties or SLAs and are intended to be supported through a community driven process. +The community module is not officially supported and should be **used at your own risk**. + +I'd like to see more tests added for things people find important. This will be done as time permits. :) + +# Contribution + +Everyone is welcome to contribute to this project. Here are the steps involved: + +1. Create a fork of the project into your own repository. +2. From your fork, create a new feature branch (other than master) that expresses your feature or enhancement. +3. Make all your necessary changes in your feature branch. +4. Create a pull request with a description on what was added or removed and details explaining the changes in lines of code. + +If approved, project owners will merge it. + +# Licensing + +Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/Templates/Update-Template.ps1 b/Templates/Update-Template.ps1 new file mode 100644 index 0000000..eec6228 Binary files /dev/null and b/Templates/Update-Template.ps1 differ diff --git a/Tests/Config.ps1 b/Tests/Config.ps1 new file mode 100644 index 0000000..738313e --- /dev/null +++ b/Tests/Config.ps1 @@ -0,0 +1,42 @@ +$global:config = @{} + +### Pester Settings + +$global:config.pester = @{ + remediate = $true +} + +### vCenter Settings + +$global:config.vcenter = @{ + vc = 172.17.48.17 +} + +### Cluster Settings + +$global:config.cluster = @{ + drsmode = 'FullyAutomated' + drslevel = 2 +} + +### ESXi Host Settings + +$global:config.host = @{ + sshenable = $true + sshwarn = 1 + esxntp = @('0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org') + esxdns = @('172.17.48.11', '172.17.48.12') + searchdomains = @('rubrik.demo') + esxsyslog = @('tcp://172.16.20.243:514') +} + +# Tegile Zebi array settings + +$global:config.nfsadvconfig = @{ + 'NFS.MaxQueueDepth' = 32 + 'NFS.DeleteRPCTimeout' = 30 + 'NFS.HeartbeatFrequency' = 20 + 'NFS.MaxVolumes' = 256 + 'Net.TcpipHeapSize' = 32 + 'Net.TcpipHeapMax' = 1536 +} \ No newline at end of file diff --git a/Tests/Update-DNS.Tests.ps1 b/Tests/Update-DNS.Tests.ps1 new file mode 100644 index 0000000..509fe3d Binary files /dev/null and b/Tests/Update-DNS.Tests.ps1 differ diff --git a/Tests/Update-DRS.Tests.ps1 b/Tests/Update-DRS.Tests.ps1 new file mode 100644 index 0000000..51f3b68 Binary files /dev/null and b/Tests/Update-DRS.Tests.ps1 differ diff --git a/Tests/Update-NFS.Tests.ps1 b/Tests/Update-NFS.Tests.ps1 new file mode 100644 index 0000000..76c43ab Binary files /dev/null and b/Tests/Update-NFS.Tests.ps1 differ diff --git a/Tests/Update-NTP.Tests.ps1 b/Tests/Update-NTP.Tests.ps1 new file mode 100644 index 0000000..5395b11 Binary files /dev/null and b/Tests/Update-NTP.Tests.ps1 differ diff --git a/Tests/Update-SSH.Tests.ps1 b/Tests/Update-SSH.Tests.ps1 new file mode 100644 index 0000000..8fb61fa Binary files /dev/null and b/Tests/Update-SSH.Tests.ps1 differ diff --git a/Tests/Update-Syslog.Tests.ps1 b/Tests/Update-Syslog.Tests.ps1 new file mode 100644 index 0000000..8cdcab0 Binary files /dev/null and b/Tests/Update-Syslog.Tests.ps1 differ diff --git a/VMware/remove-allocations.ps1 b/VMware/remove-allocations.ps1 deleted file mode 100644 index 59dd7e8..0000000 --- a/VMware/remove-allocations.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -######################################################################################################## -# Removes any VM level resource reservations and limitations -# Will fail on any service VM with a DisabledMethod preventing changes (e.g. NSX Controllers) -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules -Add-PSSnapin -Name VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather list of VMs -$VMs = Get-VM - -### Remove the reservations and limits for each VM found -$i = 1 -foreach ($VM in $VMs) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Configuring Resource Allocation Settings" -Status $VM -PercentComplete (($i / $VMs.Count) * 100) - - # Find VMs with limits or reservations - $check = Get-VMResourceConfiguration $VM - if ($check.CpuReservationMhz -ne 0 -or $check.CpuLimitMhz -ne -1 -or $check.MemReservationMB -ne 0 -or $check.MemLimitMB -ne -1) - { - - # Remove the limits and reservations - try - { - Get-VMResourceConfiguration $VM | Set-VMResourceConfiguration -CpuReservationMhz 0 -CpuLimitMhz $null -MemReservationMB 0 -MemLimitMB $null -ErrorAction:Stop | Out-Null - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: Removed reservations and limits from $VM" - } - - catch - { - Write-Host -BackgroundColor:Black -ForegroundColor:Red "Failure: Could not remove reservations and limits from $VM" - } - - } - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/remove-media.ps1 b/VMware/remove-media.ps1 deleted file mode 100644 index 5572e19..0000000 --- a/VMware/remove-media.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -######################################################################################################## -# Removes CDDrive media from the VMs -# No toggle at this point; either run it or don't :) -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules -Add-PSSnapin -Name VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather list of VMs -$VMs = Get-VM | Where {$_.PowerState -eq "PoweredOn"} - -### Comb through the VMs and disconnect CDs -$i = 1 -foreach ($VM in $VMs) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Removing Media" -Status $VM -PercentComplete (($i / $VMs.Count) * 100) - - Get-CDDrive $VM | Where {$_.ConnectionState -eq "true" -or $_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false | Out-Null - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/set-dns.ps1 b/VMware/set-dns.ps1 deleted file mode 100644 index ca69d13..0000000 --- a/VMware/set-dns.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -######################################################################################################## -# Sets the DNS entries for your ESXi servers -# Can pass along multiple entries as an array of string values -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules or snapins -$powercli = Get-PSSnapin -Name VMware.VimAutomation.Core -Registered - -try -{ - switch ($powercli.Version.Major) { - { - $_ -ge 6 - } - { - Import-Module -Name VMware.VimAutomation.Core -ErrorAction Stop - Write-Host -Object 'PowerCLI 6+ module imported' - } - 5 - { - Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop - Write-Warning -Message 'PowerCLI 5 snapin added; recommend upgrading your PowerCLI version' - } - default - { - throw 'This script requires PowerCLI version 5 or later' - } - } -} -catch -{ - throw 'Could not load the required VMware.VimAutomation.Core cmdlets' -} - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather ESXi host data for future processing -$VMHosts = Get-VMHost - -### Update DNS server info on the ESXi hosts in $vmhosts -$i = 1 -foreach ($Server in $VMHosts) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Configuring DNS Settings" -Status $Server -PercentComplete (($i / $VMHosts.Count) * 100) - - # Add desired DNS value(s) to the host - Get-VMHostNetwork $Server | Set-VMHostNetwork -DnsAddress $global:esxdns -SearchDomain $global:searchdomains | Out-Null - - # Output to console (optional) - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Server is now using DNS server(s)" (Get-VMHostNetwork $Server).DnsAddress - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/set-drs.ps1 b/VMware/set-drs.ps1 deleted file mode 100644 index df99af1..0000000 --- a/VMware/set-drs.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -######################################################################################################## -# Sets DRS configuration values for Mode and Aggressiveness# -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules -Add-PSSnapin -Name VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather cluster data for future processing -$Clusters = Get-Cluster - -### Update cluster configuration across the environment -$i = 1 -foreach ($Cluster in $Clusters) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Configuring Cluster Settings" -Status $Cluster -PercentComplete (($i / $Clusters.Count) * 100) - - # DRS Mode - Set-Cluster $Cluster -DrsAutomationLevel:$global:drsmode -Confirm:$false - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Cluster is now set to" (Get-Cluster $Cluster).DrsAutomationLevel - - # DRS Threshold (modified script from the amazing LucD) - if ($Cluster.DrsAutomationLevel -eq "FullyAutomated") - { - $ClusterView = Get-Cluster -Name $Cluster | Get-View - $ClusterSpec = New-Object VMware.Vim.ClusterConfigSpecEx - $ClusterSpec.drsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo - $ClusterSpec.drsConfig.vmotionRate = $global:drslevel - $ClusterView.ReconfigureComputeResource_Task($ClusterSpec, $true) - } - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/set-nfsconfig.ps1 b/VMware/set-nfsconfig.ps1 deleted file mode 100644 index 56af61d..0000000 --- a/VMware/set-nfsconfig.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -######################################################################################################## -# Sets the NFS advanced configuration entries for your ESXi servers -# Can pass along multiple entries as an array of string values -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + '\vars.ps1' -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules or snapins -$powercli = Get-PSSnapin -Name VMware.VimAutomation.Core -Registered - -try -{ - switch ($powercli.Version.Major) { - { - $_ -ge 6 - } - { - Import-Module -Name VMware.VimAutomation.Core -ErrorAction Stop - Write-Host -Object 'PowerCLI 6+ module imported' - } - 5 - { - Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop - Write-Warning -Message 'PowerCLI 5 snapin added; recommend upgrading your PowerCLI version' - } - default - { - throw 'This script requires PowerCLI version 5 or later' - } - } -} -catch -{ - throw 'Could not load the required VMware.VimAutomation.Core cmdlets' -} - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather ESXi host data for future processing -$VMHosts = Get-VMHost - -### Update NFS server configs on the ESXi hosts in $vmhosts -$i = 1 -foreach ($Server in $VMHosts) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity 'Configuring NFS Advanced Configuration Settings' -Status $Server -PercentComplete (($i / $VMHosts.Count) * 100) - - # Apply the desired NFS value to each host - $global:nfsadvconfig.Keys | % {Get-AdvancedSetting -Entity $Server -Name $_ | Set-AdvancedSetting -Value $global:nfsadvconfig.Item($_) -Confirm:$false} - - # Output to console (optional) - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Server is now using updated NFS advanced configuration settings" - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/set-ntp.ps1 b/VMware/set-ntp.ps1 deleted file mode 100644 index 7e39ca6..0000000 Binary files a/VMware/set-ntp.ps1 and /dev/null differ diff --git a/VMware/set-ssh.ps1 b/VMware/set-ssh.ps1 deleted file mode 100644 index 829e5f0..0000000 --- a/VMware/set-ssh.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -######################################################################################################## -# Control the state of your ESXi SSH Server status, and also optionally disable the warning -# Note: I only recommend using this in lab environments, it's not a valid security practice in prod -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules -Add-PSSnapin -Name VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather ESXi host data for future processing -$VMHosts = Get-VMHost - -### Update SSH server info on the ESXi hosts in $vmhosts -$i = 1 -foreach ($Server in $VMHosts) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Configuring SSH Settings" -Status $Server -PercentComplete (($i / $VMHosts.Count) * 100) - - # SSH Server status - if ($global:sshenable -eq $true) {Start-VMHostService -HostService ($Server | Get-VMHostService | Where { $_.Key -eq “TSM-SSH” } ) | Out-Null} - else {Stop-VMHostService -HostService ($Server | Get-VMHostService | Where { $_.Key -eq “TSM-SSH” } ) | Out-Null} - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Server SSH Running status is now" (Get-VMHostService $Server | Where { $_.Key -eq “TSM-SSH” }).Running - - # Disable SSH Warning (UserVars) - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Server Shell Warning Supression is set to" (Get-AdvancedSetting -Entity $Server | Where {$_.Name -eq "UserVars.SuppressShellWarning"} | Set-AdvancedSetting -Value "$global:sshwarn" -Confirm:$false).Value - - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/VMware/set-syslog.ps1 b/VMware/set-syslog.ps1 deleted file mode 100644 index cb95ef2..0000000 --- a/VMware/set-syslog.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -######################################################################################################## -# Sets the syslog server value for your ESXi hosts -# You can pass along an array of strings for multiple remote syslog servers -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -### Import modules -Add-PSSnapin -Name VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -### Connect to vCenter -Connect-VIServer $global:vc - -### Gather ESXi host data for future processing -$VMHosts = Get-VMHost - -### Update Syslog server info on the ESXi hosts in $vmhosts -$i = 1 -foreach ($Server in $VMHosts) - { - # Everyone loves progress bars, so here is a progress bar - Write-Progress -Activity "Configuring Syslog Settings" -Status $Server -PercentComplete (($i / $VMHosts.Count) * 100) - - # Set the syslog server properties - try - { - Set-VMHostSysLogServer -VMHost $Server -SysLogServer $global:esxsyslog -ErrorAction Stop | Out-Null - (Get-EsxCli -VMHost $Server).system.syslog.reload() | Out-Null - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Success: $Server is now using $global:esxsyslog" - } - catch - { - Write-Host -BackgroundColor:Black -ForegroundColor:Green "Failure: $Server could not be configured" - } - - - $i++ - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/Windows/Set-WindowsDNS.ps1 b/Windows/Set-WindowsDNS.ps1 deleted file mode 100644 index 5d2c3f4..0000000 --- a/Windows/Set-WindowsDNS.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -#=======================================================================# -# Set DNS Server entries for clients -#=======================================================================# - -# Snapins -Install-WindowsFeature -Name RSAT-AD-PowerShell -Import-Module ActiveDirectory - -# Creds -Invoke-Expression ($PSScriptRoot + "\JobVars.ps1") - -# Domain Controller 1 -$wmi = Get-WmiObject win32_networkadapterconfiguration -ComputerName "dc1.glacier.local" -filter "ipenabled = 'true'" -$wmi.SetDNSServerSearchOrder($DNSServersDC1) | Out-Null - -# Domain Controller 2 -$wmi = Get-WmiObject win32_networkadapterconfiguration -ComputerName "dc2.glacier.local" -filter "ipenabled = 'true'" -$wmi.SetDNSServerSearchOrder($DNSServersDC2) | Out-Null - -# Add the AD module so that we can query for computer objects -Install-WindowsFeature -Name RSAT-AD-PowerShell -Import-Module ActiveDirectory - -# Get a list of all the computer objects that AD is aware of -$pclist = get-adcomputer -Filter 'ObjectClass -eq "Computer"' | select -ExpandProperty DNSHostName - -# Run through the list and set the DNS server entries for each computer object -foreach ($_ in $pclist) { - if ($_ -notmatch "DC*") { - Write-Host "Connecting to $_" - $wmi = Get-WmiObject win32_networkadapterconfiguration -ComputerName $_ -filter "ipenabled = 'true'" - $wmi.SetDNSServerSearchOrder($DNSServers) | Out-Null - } - } \ No newline at end of file diff --git a/Windows/Update-TemplateVM.ps1 b/Windows/Update-TemplateVM.ps1 deleted file mode 100644 index 2993c8f..0000000 --- a/Windows/Update-TemplateVM.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -######################################################################################################## -# Triggers a full set of Windows Updates on Windows VMs in a template folder -######################################################################################################## - -# Pull in vars -$vars = (Get-Item $PSScriptRoot).Parent.FullName + "\vars.ps1" -Invoke-Expression ($vars -replace ' ', '` ') - -# Add the required modules -Import-Module PSWindowsUpdate -Add-PSSnapin VMware.VimAutomation.Core - - # Ignore self-signed SSL certificates for vCenter Server (optional) - Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false - -# Connect to vCenter Server -Connect-VIServer $global:vc - -# Get a list of template VMs -$VMs = Get-VM -Location (Get-Folder -Name "Templates") - -foreach ($VM in $VMs) - { - - if ($VM.PowerState -eq "PoweredOn" -and $VM.Guest.OSFullName -match "Microsoft") - { - - # Copy over the PSWindowsUpdate module to the target server - Copy-Item "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate" -Destination ("\\" + $VM.Guest.HostName + "\C$\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate") -Recurse - - # Create a script block for the WUInstaller - $Script = {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log} - - # Start up a remote task to download updates, install them, and then auto reboot - Invoke-WUInstall -ComputerName $VM.Guest.HostName -Script $Script -Confirm:$false -TaskName ("WinUpdate-" + (Get-Date).Second) - - # Pull the report showing what KBs are being downloaded and accepted. I tend to leave this commented unless tshooting. - #Get-Content ("\\" + $VM.Guest.HostName + "\C$\PSWindowsUpdate.log") - - } - - } - -Disconnect-VIServer -Confirm:$false \ No newline at end of file diff --git a/engine.ps1 b/engine.ps1 deleted file mode 100644 index 4bb1dc7..0000000 Binary files a/engine.ps1 and /dev/null differ diff --git a/vars.ps1 b/vars.ps1 deleted file mode 100644 index c38a66a..0000000 Binary files a/vars.ps1 and /dev/null differ