{"id":89,"date":"2021-06-30T13:46:17","date_gmt":"2021-06-30T17:46:17","guid":{"rendered":"https:\/\/nobrandsan.com\/wordpress\/?p=89"},"modified":"2021-07-02T14:55:36","modified_gmt":"2021-07-02T18:55:36","slug":"powershell-scripting-global-config","status":"publish","type":"post","link":"https:\/\/nobrandsan.com\/wordpress\/index.php\/2021\/06\/30\/powershell-scripting-global-config\/","title":{"rendered":"PowerShell Scripting Global Config"},"content":{"rendered":"\n<p>My approach to scripting is to make things a reusable as possible.  Hence,  I always start things off from with the following global config file and script template.<\/p>\n\n\n\n<p>CONFIG.ps1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$hosts = @(\"vcenter.local\")\n$VBRServer = \"veeam.local\"\n$OUTPUTDIR = \"c:\\Shares\\LOGS\"\n#$CREDS = Get-Credential\n#####$CREDS | Export-Clixml c:\\Shares\\Scripts\\admin.creds\n$CREDS = Import-Clixml -Path c:\\Shares\\Scripts\\admin.creds\n$SMTPServer = \"mail.local\"\n$SMTPPort = 25\n$SMTPFrom = \"tasker@mail.local\"\n$SMTPTo = \"root@mail.local\"\n$VMExcludelist = @(\"vm1.local\", \"vm2.local\", \"VMware vCenter Server\")\n\n$CLUSTERExcludeList = @()\n$Post = $True<\/code><\/pre>\n\n\n\n<p>Base-Template.ps1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>##\n## Written By Brian Vogel bfvogel@gmail.com \n## MIT License\n##\n##\nparam (\n&#91;Parameter(Mandatory=$true)]&#91;string]$CHANGEME,\n&#91;switch]$Script = $false,\n&#91;switch]$Automatic = $false\n\n)\n\n\n### Script Config Vars\n\n\n\n\n\n##\n$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent\ntry {\n\t. (\"$ScriptDirectory\\Config.ps1\")\n}\ncatch {\n\tWrite-Host \"Error while loading supporting PowerShell Scripts\" \n\texit 1\n}\n\n\n\n## Module Load\nif (!(Get-Module -Name VMware.VimAutomation.Core) -and (Get-Module -ListAvailable -Name VMware.VimAutomation.Core)) {  \n\tWrite-Output \"loading the VMware COre Module...\"  \n\tif (!(Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {  \n\t\t# Error out if loading fails  \n\t\tWrite-Error \"`nERROR: Cannot load the VMware Module. Is the PowerCLI installed?\"  \n\t}  \n\t$Loaded = $True  \n}  \nelseif (!(Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -and !(Get-Module -Name VMware.VimAutomation.Core) -and ($Loaded -ne $True)) {  \n\tWrite-Output \"loading the VMware Core Snapin...\"  \n\tif (!(Add-PSSnapin -PassThru VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {  \n\t\t# Error out if loading fails  \n\t\tWrite-Error \"`nERROR: Cannot load the VMware Snapin or Module. Is the PowerCLI installed?\"  \n\t\tWrite-Host \"Try: 'Install-Module VMware.PowerCLI'\"\n\t}  \n}  \n\nConnect-VIServer $hosts -Credential $CREDS | out-null\n\n########START Script########################\n\n\n########END Script##########################\n\nDisconnect-VIServer * -confirm:$false<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My approach to scripting is to make things a reusable as possible. Hence, I always start things off from with the following global config file and script template. CONFIG.ps1 Base-Template.ps1<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[1],"tags":[5,6,4],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-powershell","tag-scripting","tag-vmware"],"_links":{"self":[{"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":2,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nobrandsan.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}