<commit_before>function Create-NSXTier {



[CmdletBinding()]

Param(

	[Parameter(Mandatory=$true,Position=0,HelpMessage="NSX Manager IP or FQDN")]

	[ValidateNotNullorEmpty()]

	[String]$NSX,

	[Parameter(Mandatory=$true,Position=1,HelpMessage="NSX Manager credentials with administrative authority")]

	[ValidateNotNullorEmpty()]

	[System.Security.SecureString]$NSXPassword,

	[Parameter(Mandatory=$true,Position=2,HelpMessage="Path to your JSON configuration file")]

	[ValidateNotNullorEmpty()]

	[String]$JSONPath,

	[Parameter(Mandatory=$true,Position=3,HelpMessage="vCenter Server IP or FQDN")]

	[ValidateNotNullorEmpty()]

	[String]$vCenter,

	[String]$NSXUsername = "admin"

	)



Process {



# Create NSX authorization string and store in $head

$nsxcreds = New-Object System.Management.Automation.PSCredential "admin",$NSXPassword

$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername+":"+$($nsxcreds.GetNetworkCredential().password)))

$head = @{"Authorization"="Basic $auth"}

$uri = "https://$nsx"



# Plugins and version check

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction:SilentlyContinue

Add-PSSnapin VMware.VimAutomation.Vds -ErrorAction:SilentlyContinue

if ($Host.Version.Major -lt 3) {throw "PowerShell 3 or higher is required"}



# Parse configuration from json file

$config = Get-Content -Raw -Path $jsonpath | ConvertFrom-Json

	if ($config) {Write-Host -BackgroundColor:Black -ForegroundColor:Yellow "Status: Parsed configuration from json file."}

	else {throw "I don't have a config, something went wrong."}



# Combine switches and transit into a build list (easier than messing with a custom PS object!)

$switchlist = @()

foreach ($_ in $config.switches) {$switchlist += $_.name}

$switchlist += $config.transit.name



# Get MoRefs for the vSphere components

if (-not $vcentercreds) {$vcentercreds = Get-Credential -Message "vCenter Server credentials"}

Connect-VIServer -Server $vCenter -Credential $vcentercreds | Out-Null

$moref = @{}

$moref.Add("datacenter",(Get-Datacenter $config.vsphere.datacenter | Get-View).MoRef.Value)

$moref.Add("cluster",(Get-Cluster $config.vsphere.cluster | Get-View).MoRef.Value)

$moref.Add("rp",(Get-ResourcePool -Location (Get-Cluster $config.vsphere.cluster) | Get-View).MoRef.Value)

$moref.Add("datastore",(Get-Datastore $config.vsphere.datastore | Get-View).MoRef.Value)

$moref.Add("folder",(Get-Folder $config.vsphere.folder | Get-View).MoRef.Value)

$moref.Add("edge_uplink",(Get-VDPortgroup $config.edge.uplink.iface | Get-View).MoRef.Value)

$moref.Add("edge_mgmt",(Get-VDPortgroup $config.edge.management.iface | Get-View).MoRef.Value)

$moref.Add("router_mgmt",(Get-VDPortgroup $config.router.management.iface | Get-View).MoRef.Value)
<commit_msg>fixed respool bug, added noaskcreds switch for vC<commit_after>function Create-NSXTier {



[CmdletBinding()]

Param(

	[Parameter(Mandatory=$true,Position=0,HelpMessage="NSX Manager IP or FQDN")]

	[ValidateNotNullorEmpty()]

	[String]$NSX,

	[Parameter(Mandatory=$true,Position=1,HelpMessage="NSX Manager credentials with administrative authority")]

	[ValidateNotNullorEmpty()]

	[System.Security.SecureString]$NSXPassword,

	[Parameter(Mandatory=$true,Position=2,HelpMessage="Path to your JSON configuration file")]

	[ValidateNotNullorEmpty()]

	[String]$JSONPath,

	[Parameter(Mandatory=$true,Position=3,HelpMessage="vCenter Server IP or FQDN")]

	[ValidateNotNullorEmpty()]

	[String]$vCenter,

	[String]$NSXUsername = "admin",

	[Parameter(HelpMessage="Use your current login credentials for vCenter")]

	[Switch]$NoAskCreds

	)



Process {



# Create NSX authorization string and store in $head

$nsxcreds = New-Object System.Management.Automation.PSCredential "admin",$NSXPassword

$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername+":"+$($nsxcreds.GetNetworkCredential().password)))

$head = @{"Authorization"="Basic $auth"}

$uri = "https://$nsx"



# Plugins and version check

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction:SilentlyContinue

Add-PSSnapin VMware.VimAutomation.Vds -ErrorAction:SilentlyContinue

if ($Host.Version.Major -lt 3) {throw "PowerShell 3 or higher is required"}



# Parse configuration from json file

$config = Get-Content -Raw -Path $jsonpath | ConvertFrom-Json

	if ($config) {Write-Host -BackgroundColor:Black -ForegroundColor:Yellow "Status: Parsed configuration from json file."}

	else {throw "I don't have a config, something went wrong."}



# Combine switches and transit into a build list (easier than messing with a custom PS object!)

$switchlist = @()

foreach ($_ in $config.switches) {$switchlist += $_.name}

$switchlist += $config.transit.name



# Get MoRefs for the vSphere components

if ($NoAskCreds -eq $false) {

	$vcentercreds = Get-Credential -Message "vCenter Server credentials"

	Connect-VIServer -Server $vCenter -Credential $vcentercreds | Out-Null

	}

else {Connect-VIServer -Server $vCenter | Out-Null}

$moref = @{}

$moref.Add("datacenter",(Get-Datacenter $config.vsphere.datacenter | Get-View).MoRef.Value)

$moref.Add("cluster",(Get-Cluster $config.vsphere.cluster | Get-View).MoRef.Value)

$moref.Add("rp",(Get-ResourcePool -Location (Get-Cluster $config.vsphere.cluster) -Name "Resources" | Get-View).MoRef.Value)

$moref.Add("datastore",(Get-Datastore $config.vsphere.datastore | Get-View).MoRef.Value)

$moref.Add("folder",(Get-Folder $config.vsphere.folder | Get-View).MoRef.Value)

$moref.Add("edge_uplink",(Get-VDPortgroup $config.edge.uplink.iface | Get-View).MoRef.Value)

$moref.Add("edge_mgmt",(Get-VDPortgroup $config.edge.management.iface | Get-View).MoRef.Value)

$moref.Add("router_mgmt",(Get-VDPortgroup $config.router.management.iface | Get-View).MoRef.Value)

{'fraction_non_alphanumeric': 0.5692896935933147, 'fraction_numerical': 0.0015668523676880223, 'mean_word_length': 12.792316926770708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2595167', 'n_tokens_mistral': 11428, 'n_tokens_neox': 11427, 'n_words': 385}