This commit is contained in:
Zack Meier
2026-04-15 15:45:50 -05:00
commit 1d304511b8
613 changed files with 140998 additions and 0 deletions
@@ -0,0 +1,36 @@
<#
.Synopsis
Connects to ITD's vCenter servers
.DESCRIPTION
Connects to ITD's vCenter servers
.EXAMPLE
Connect-ITDvCenter -Credential $PSCredential
#>
function Connect-ITDvCenter {
[CmdletBinding()]
Param
(
[PSCredential]
$Credential
)
Begin {
Import-Module VMware.VimAutomation.Core
$VIServers = "itdvmvc1.nd.gov", "itdvmvc2.nd.gov"
}
Process {
If ($Global:DefaultVIServers) {
Write-Verbose "VIServers already connected"
}
Else {
If ($Credential) {
Connect-VIServer -Server $VIServers -Credential $Credential | Out-Null
}
Else {
Connect-VIServer -Server $VIServers | Out-Null
}
}
}
End {
}
}
@@ -0,0 +1,57 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Disable-ITDVMwareVMHostFeature {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]
$Name,
[switch]
$LockdownMode,
[switch]
$SSH,
[switch]
$AlarmActions
)
Begin {
}
Process {
$VMHosts = Get-VMHost -Name $Name
ForEach ($VMHost in $VMHosts) {
If ($LockdownMode) {
($VMHost | Get-View).ExitLockdownMode()
}
If ($SSH) {
Get-VMHostService -VMHost $VMHost | Where-Object { $_.key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Select-Object VMHost, Key, Label, Running
}
If ($AlarmActions) {
$VIServer = $VMHost.Uid.Split('@')[1].Split(':')[0]
$alarmMgr = Get-View AlarmManager -Server $VIServer
$alarmEnabled = $VMHost.ExtensionData.AlarmActionsEnabled
if ($alarmEnabled -eq $true) {
$alarmMgr.EnableAlarmActions($VMHost.ExtensionData.MoRef, $false)
}
}
}
}
End {
}
}
@@ -0,0 +1,23 @@
<#
.Synopsis
Disconnects from ITD's vCenter servers
.DESCRIPTION
Disconnects from ITD's vCenter servers
.EXAMPLE
Disconnect-ITDvCenter
#>
function Disconnect-ITDvCenter {
[CmdletBinding()]
Param
(
)
Begin {
$VIServers = "itdvmvc1.nd.gov", "itdvmvc2.nd.gov"
}
Process {
Disconnect-VIServer -Server $VIServers -Confirm:$false
}
End {
}
}
@@ -0,0 +1,57 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Enable-ITDVMwareVMHostFeature {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]
$Name,
[switch]
$LockdownMode,
[switch]
$AlarmActions,
[switch]
$SSH
)
Begin {
}
Process {
$VMHosts = Get-VMHost -Name $Name
ForEach ($VMHost in $VMHosts) {
If ($LockdownMode) {
($VMHost | Get-View).EnterLockdownMode()
}
If ($SSH) {
Get-VMHostService -VMHost $VMHost | Where-Object { $_.key -eq 'TSM-SSH' } | Start-VMHostService -Confirm:$false | Select-Object VMHost, Key, Label, Running
}
If ($AlarmActions) {
$VIServer = $VMHost.Uid.Split('@')[1].Split(':')[0]
$alarmMgr = Get-View AlarmManager -Server $VIServer
$alarmEnabled = $VMHost.ExtensionData.AlarmActionsEnabled
if ($alarmEnabled -eq $false) {
$alarmMgr.EnableAlarmActions($VMHost.ExtensionData.MoRef, $true)
}
}
}
}
End {
}
}
@@ -0,0 +1,33 @@
$PowerBi = Import-Csv -Path D:\Downloads\serverinventory20251002.csv
$SRM = Import-Csv -Path D:\Downloads\itdvmvc1.nd.gov-itdvmvc2.nd.gov-20251002-102657.csv
$VMs = Get-VM | Where-Object { $_.ExtensionData.summary.config.ManagedBy.Type -eq "placeholderVm" }
$Result = [System.Collections.ArrayList]@()
foreach ($pbi in $PowerBi) {
Write-Verbose -Message ($pbi.'Host Name') -Verbose
$obj = $null
$obj = [PSCustomObject]@{
PowerBi = $pbi.'Host Name'
Placeholder = $VMs | Where-Object Name -EQ $pbi.'Host Name' | Select-Object -ExpandProperty Name -First 1;
SRM = $SRM | Where-Object "Virtual Machine" -EQ $pbi.'Host Name' | Select-Object -ExpandProperty "Virtual Machine"
CMDB = ((Get-ITDServiceNowRecord -Table cmdb_ci_server -Filter ("name=" + $pbi.'Host Name'.split('.')[0])).name.display_value)
}
$null = $Result.Add($obj)
}
foreach ($VM in $VMs) {
if ($Result | Where-Object Placeholder -EQ $VM.Name) {
#do nothing
}
else {
Write-Verbose -Message ($VM.Name) -Verbose
$obj = [PSCustomObject]@{
PowerBi = $PowerBi | Where-Object 'Host Name' -EQ $pbi.'Host Name'
Placeholder = $VM.Name;
SRM = $SRM | Where-Object "Virtual Machine" -EQ $pbi.'Host Name'
CMDB = ((Get-ITDServiceNowRecord -Table cmdb_ci_server -Filter ("name=" + $pbi.'Host Name'.split('.')[0])).name.display_value);
}
$null = $Result.Add($obj)
}
}
@@ -0,0 +1,58 @@
<#
.SYNOPSIS
Usage report for VMware datastores.
.DESCRIPTION
Usage report for VMware datastores.
.NOTES
Requires VMware PowerCLI module.
Requires connection to vCenter.
.EXAMPLE
Get-ITDVMwareDatastoreReport
Retrieves a report of all datastores in the vCenter.
.EXAMPLE
Get-ITDVMwareDatastoreReport -Name "*78*"
Retrieves a report of all datastores in the vCenter that match the name pattern "*78*".
.PARAMETER Name
The name of the datastore to retrieve. If not specified, all datastores will be returned.
Supports wildcards.
#>
function Get-ITDVMwareDatastoreReport {
[CmdletBinding()]
param (
[string]
$Name
)
begin {
}
process {
if ($PSBoundParameters.ContainsKey('Name')) {
$AllDatastores = Get-Datastore -Name $Name
}
else {
$AllDatastores = Get-Datastore
}
foreach ($Datastore in $AllDatastores) {
$FreeSpaceGB = $Datastore.FreeSpaceGB
$CapacityGB = $Datastore.CapacityGB
$UsedSpaceGB = $CapacityGB - $FreeSpaceGB
$obj = [PSCustomObject]@{
Name = $Datastore.Name;
Datacenter = $Datastore.Datacenter.Name
FreeSpaceGB = $FreeSpaceGB;
UsedSpaceGB = ($CapacityGB - $FreeSpaceGB);
CapacityGB = $CapacityGB;
FreePercent = [math]::round($Datastore.FreeSpaceGB / $Datastore.CapacityGB * 100, 2);
}
#$null = $Result.Add($obj)
Write-Output $obj
}
}
end {
}
}
@@ -0,0 +1,73 @@
# servicenow cmdb ci dr protection
# vcenter placeholder
$AllVMwareVMs = Get-Datacenter | Where-Object {$_.Name -like "*Primary*" -or $_.Name -like "*Secondary*" -or $_.Name -like "*DCN*"} | Get-VM | Where-Object { $_.Name -notlike "vCLS*" } | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -ne "placeholderVm" } | Sort-Object Name
$AllVMwarePlaceholders = $AllVMwareVMs | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -eq "placeholderVm" }
$AllCmdbCi = Get-ITDServiceNowRecord -Table cmdb_ci_server -Filter "operational_status!=6^u_nd_dr_protectionLIKEVMware" -IncludeTotalCount | Select-Object @{n = 'CiName'; e = { $_.name.display_value } }, @{n = 'CiFqdn'; e = { $_.fqdn.display_value } }, @{n = 'CiOpStatus'; e = { $_.operational_status.display_value } }, @{n = 'DRProtection'; e = { $_.u_nd_dr_protection.display_value } } | Sort-Object CiName
$ArrayList = [System.Collections.ArrayList]@()
# check for placeholder
ForEach ($Ci in $AllCmdbCi) {
$PlaceholderBool = $null
$VMBool = $null
If($AllVMwareVMs | Where-Object { $_.Name -eq $Ci.CiFqdn }) {
$VMBool = $true
}
else {
$VMBool = $false
}
If ($AllVMwarePlaceholders | Where-Object { $_.Name -eq $Ci.CiFqdn }) {
$PlaceholderBool = $true
}
else {
$PlaceholderBool = $false
}
$obj = [PSCustomObject]@{
CiName = $Ci.CiName
CiFqdn = $Ci.CiFqdn
CiOpStatus = $Ci.CiOpStatus
DRProtection = $Ci.DRProtection
VMExists = $VMBool
Placeholder = $PlaceholderBool
}
$null = $ArrayList.Add($obj)
}
# verify no extra entries in vm list / confirm all vms have cmdb entries
ForEach ($VM in $AllVMwareVMs) {
If (-not ($ArrayList | Where-Object { $_.CiFqdn -eq $VM.Name })) {
#Write-Host "VM $($VM.Name) does not have a corresponding CMDB entry." -ForegroundColor Red
$obj = [PSCustomObject]@{
CiName = $null
CiFqdn = $null
CiOpStatus = $null
DRProtection = $null
VMExists = $VM.Name
PlaceholderExists = $null
}
$null = $ArrayList.Add($obj)
}
}
# verify no extra entries in placeholder list / confirm all placeholders have cmdb entries
ForEach ($Placeholder in $AllVMwarePlaceholders) {
If (-not ($ArrayList | Where-Object { $_.CiFqdn -eq $Placeholder.Name })) {
#Write-Host "Placeholder VM $($Placeholder.Name) does not have a corresponding CMDB entry." -ForegroundColor Red
$obj = [PSCustomObject]@{
CiName = $null
CiFqdn = $Placeholder.Name
CiOpStatus = $null
DRProtection = $null
VMExists = $null
PlaceholderExists = $true
}
$null = $ArrayList.Add($obj)
}
}
$ArrayList | Sort-Object CiFqdn | Format-Table -AutoSize
@@ -0,0 +1,42 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
.INPUTS
Inputs to this cmdlet (if any)
.OUTPUTS
Output from this cmdlet (if any)
.NOTES
General notes
.COMPONENT
The component this cmdlet belongs to
.ROLE
The role this cmdlet belongs to
.FUNCTIONALITY
The functionality that best describes this cmdlet
#>
function Get-ITDVMwareVMHAEventList {
[CmdletBinding()]
Param
(
)
begin {
}
process {
$Date = Get-Date
$HAVMrestartold = 5
Get-VIEvent -MaxSamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type warning | Where-Object { $_.FullFormattedMessage -match "restarted" } | Select-Object CreatedTime, ObjectName, FullFormattedMessage | Sort-Object CreatedTime -Descending
}
end {
}
}
@@ -0,0 +1,61 @@
<#
.SYNOPSIS
Retrieves HBA (Host Bus Adapter) device information, including WWN (World Wide Name) and WWP (World Wide Port Name), for specified VMware ESXi hosts.
.DESCRIPTION
This function connects to one or more VMware ESXi hosts and gathers detailed information about their HBA devices. The information collected includes the device name, WWN, WWP, and other relevant properties. This is useful for inventory, troubleshooting, or auditing storage connectivity in a VMware environment.
.PARAMETER VMHost
Specifies the ESXi host(s) from which to retrieve HBA information. Accepts one or more host names or objects.
.EXAMPLE
Get-ITDVMwareVMHostHBA -VMHost "esxi01.domain.local"
Retrieves HBA information from the specified ESXi host.
.EXAMPLE
Get-ITDVMwareVMHostHBA
Retrieves HBA information from all connected ESXi hosts.
#>
function Get-ITDVMwareVMHostHBA {
[CmdletBinding()]
param (
[string]
$VMHostName
)
begin {
}
process {
If ($PSBoundParameters.ContainsKey('VMHostName')) {
$AllVMHosts = Get-VMHost -Name $VMHostName
}
Else {
$AllVMHosts = Get-VMHost
}
ForEach ($VMHost in $AllVMHosts) {
$HBAs = $null
$HBAs = Get-VMHostHba -VMHost $VMHost -Type FibreChannel
ForEach ($HBA in $HBAs) {
$wwn = "{0:X}" -f $HBA.NodeWorldWideName
$wwp = "{0:X}" -f $HBA.PortWorldWideName
$obj = [PSCustomObject]@{
'VMHostName' = $VMHost.Name;
'Device' = $HBA.Device;
'Model' = $HBA.Model;
'Status' = $HBA.Status;
'NodeWorldWideName' = (0..7 | ForEach-Object { $wwn.Substring($_ * 2, 2) }) -join ':'
'PortWorldWideName' = (0..7 | ForEach-Object { $wwp.Substring($_ * 2, 2) }) -join ':'
}
Write-Output $obj
}
}
}
end {
}
}
@@ -0,0 +1,41 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Get-ITDVMwareVMHostStatus {
[CmdletBinding()]
param (
[string[]]
$Name
)
Begin {
}
Process {
If ($Name) {
Get-VMHost -Name $Name | Select-Object Name, ConnectionState, `
@{n = 'AlarmActionsEnabled'; e = { $_.ExtensionData.AlarmActionsEnabled } }, `
@{n = "LockdownMode"; e = { $_.ExtensionData.Config.LockdownMode } }, `
@{n = 'TSM-SSH'; e = { ($_ | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" }).Running } }
}
Else {
Get-VMHost | Select-Object Name, ConnectionState, `
@{n = 'AlarmActionsEnabled'; e = { $_.ExtensionData.AlarmActionsEnabled } }, `
@{n = "LockdownMode"; e = { $_.ExtensionData.Config.LockdownMode } }, `
@{n = 'TSM-SSH'; e = { ($_ | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" }).Running } }
}
}
End {
}
}
@@ -0,0 +1,209 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function New-ITDVMNetwork {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]
$CIDR,
[Parameter(Mandatory = $true)]
[ValidateLength(3, 4)]
[string]
$VlanId,
[Parameter(Mandatory = $true)]
[ValidateSet("Data-Server", "Data-User")]
[string]
$DataType,
#[PSCredential]
#$SharePointCredential,
[PSCredential]
$vCenterCredential
)
begin {
If ($VlanId -eq "MAC" -or $VlanId -eq "MAG") {
$Hypervisor = "Azure"
}
Else {
$Hypervisor = "VMware"
}
Write-Verbose "Hypervisor $Hypervisor"
#VMware
If ($Hypervisor -eq "VMware") {
$ConnectITDvCenterParams = @{ }
If ($vCenterCredential) { $ConnectITDvCenterParams += @{Credential = $vCenterCredential } }
Connect-ITDvCenter @ConnectITDvCenterParams
switch ($DataType) {
'Data-Server' {
$BismarckVDSwitch = 'dvSwitch-PDC-Data-Server'
$MandanVDSwitch = 'dvSwitch-SDC-Data-Server'
}
'Data-User' {
$BismarckVDSwitch = 'dvSwitch-PDC-Data-User'
$MandanVDSwitch = 'dvSwitch-SDC-Data-User'
}
}
$PortGroupList = Get-VirtualPortGroup
}
<#SharePoint
$InvokeWebRequestParams = $null
If ($SharePointCredential) { $InvokeWebRequestParams += @{Credential = $SharePointCredential } }
Else { $InvokeWebRequestParams += @{UseDefaultCredentials = $true } }
$UrlContextInfo = "https://share.nd.gov/itd/computer-systems/distributed-systems/vmware/_api/contextinfo"
$InvokeWebRequestParams = @{
Uri = $UrlContextInfo;
Method = "Post";
UseBasicParsing = $true;
}
If ($Credential) { $InvokeWebRequestParams += @{Credential = $Credential } }
Else { $InvokeWebRequestParams += @{UseDefaultCredentials = $true } }
#$RequestDigest = Invoke-RestMethod -Uri $UrlContextInfo -Method Post -UseDefaultCredentials
$RequestDigest = Invoke-RestMethod @InvokeWebRequestParams
$RequestDigest = $RequestDigest.GetContextWebInformation.FormDigestValue
$UrlList = "https://share.nd.gov/itd/computer-systems/distributed-systems/vmware/_api/lists/getbytitle('VM Networks')"
$InvokeWebRequestParams = @{
Uri = $UrlList;
UseBasicParsing = $true;
}
If ($Credential) { $InvokeWebRequestParams += @{Credential = $Credential } }
Else { $InvokeWebRequestParams += @{UseDefaultCredentials = $true } }
#$List = Invoke-RestMethod -uri $UrlList -UseDefaultCredentials
$List = Invoke-RestMethod @InvokeWebRequestParams
$ListItemEntityTypeFullName = $list.entry.content.properties.ListItemEntityTypeFullName
$UrlListItems = "https://share.nd.gov/itd/computer-systems/distributed-systems/vmware/_api/lists/getbytitle('VM Networks')/items" + '?$top=10000'
$header = @{
"accept" = "application/json;odata=verbose"
"X-RequestDigest" = $RequestDigest
}
#>
}
process {
try {
<#
If ($SharePointCredential) { $GetITDVMwareSharePointNetworkListParams += @{Credential = $SharePointCredential } }
$NetworkList = Get-ITDVMwareSharePointNetworkList @GetITDVMwareSharePointNetworkListParams
#>
$NetworkId = $CIDR.split('/')[0]
$NetworkMask = $CIDR.split('/')[1]
If ($VlanId -match "^\d+$" -and $VlanId.length -eq 3) {
$VlanId = "0" + $VlanId
}
<# Verify CIDR not already in SharePoint
If (@($NetworkList | Where-Object CIDR -EQ $CIDR)) {
Write-Error "CIDR already exists in SharePoint"
}
#>
# If VMware, do more checks then create port group
If ($Hypervisor -eq "VMware") {
# verify VlanId not already in sharepoint
If (@($NetworkList | Where-Object Vlan_Id -EQ $VlanId)) {
Write-Error "Vlan Id already exists in SharePoint"
Exit
}
# verify Vlan Id not already in vmware portgroup
If (@($PortGrouplist | Where-Object { $_.Name.split('_')[2] -eq $NetworkId })) {
Write-Error "Network_Id already exists in VMware PortGroup name"
Exit
}
If (@($PortGrouplist | Where-Object { $_.Name.split('_')[1] -eq $VlanId } )) {
Write-Error "VlanId already exists in VMware PortGroup name"
Exit
}
# Add new port group to VMware
$PGName = "dvPG_" + $VlanId + "_" + $NetworkId + "_" + $NetworkMask
Get-VDSwitch -Name $BismarckVDSwitch | New-VDPortgroup -Name $PGName -NumPorts 1 -VlanId $VlanId
Get-VDSwitch -Name $BismarckVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -FailoverDetectionPolicy BeaconProbing
Get-VDSwitch -Name $BismarckVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -BlockOverrideAllowed $false -ResetPortConfigAtDisconnect $false
Get-VDSwitch -Name $BismarckVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDSecurityPolicy | Set-VDSecurityPolicy -MacChanges $false -AllowPromiscuous $false
Get-VDSwitch -Name $MandanVDSwitch | New-VDPortgroup -Name $PGName -NumPorts 1 -VlanId $VlanId
Get-VDSwitch -Name $MandanVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -FailoverDetectionPolicy BeaconProbing
Get-VDSwitch -Name $MandanVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -BlockOverrideAllowed $false -ResetPortConfigAtDisconnect $false
Get-VDSwitch -Name $MandanVDSwitch | Get-VDPortgroup | Where-Object { $_.Name -like ("*_" + $VlanId + "_*") } | Get-VDSecurityPolicy | Set-VDSecurityPolicy -MacChanges $false -AllowPromiscuous $false
}
# Get PA7050 Zone info
If ($Hypervisor -eq "Azure") {
$Secure = "True"
$PA_Zone = "Azure"
$AutoUpdate = $false
}
If ($Hypervisor -eq "VMware") {
#$PAInterface = Get-ITDPAInterface -Number ($VlanId.TrimStart('0'))
#If (@($PAInterface).count -gt 1) {
# Write-Error "More than one PA Interface found"
# exit
#}
#else {
# $Secure = [string]$PAInterface.ZeroTrust
# $PA_Zone = $PAInterface.Zone
# $AutoUpdate = $true
#}
}
<# Add to SharePoint
[PSCustomObject]$NewRecord = @{
"__metadata" = @{type = $ListItemEntityTypeFullName }
}
$NewRecord += @{Title = ("new_" + $env:USERNAME) }
$NewRecord += @{CIDR = $CIDR }
$NewRecord += @{DataType = $DataType }
$NewRecord += @{Vlan_Id = $VlanId }
$NewRecord += @{PA_Zone = $PA_Zone }
$NewRecord += @{Secure = $Secure }
$NewRecord += @{AutoUpdate = $AutoUpdate }
$InvokeWebRequestParams = @{
Uri = $UrlListItems;
Method = "Post";
Body = $NewRecord | ConvertTo-Json;
ContentType = "application/json;odata=verbose";
Headers = $Header;
UseBasicParsing = $AutoUpdate;
}
If ($SharePointCredential) { $InvokeWebRequestParams += @{Credential = $SharePointCredential } }
Else { $InvokeWebRequestParams += @{UseDefaultCredentials = $true } }
Invoke-RestMethod @InvokeWebRequestParams
#>
}
catch {
Write-Error $error[0]
}
}
end {
}
}
@@ -0,0 +1,49 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Remove-ITDVMwareCdDriveMedia {
[CmdletBinding()]
Param
(
[string[]]
$ComputerName,
[PSCredential]
$Credential
)
Begin {
Connect-ITDvCenter -Credential $Credential
Write-Verbose "Connected to: $global:DefaultVIServers"
If ($global:DefaultVIServers.Count -gt 0) {
Write-Verbose "connected to VI server(s)"
}
Else {
Write-Warning "not connected to any VIservers, stopping script"
break
break
}
}
Process {
ForEach ($c in $ComputerName) {
$CurrentVM = $null
$CurrentVM = Get-VM -Name $c
$CurrentVM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false
}
}
End {
}
}
@@ -0,0 +1,34 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Remove-ITDVMwareOSCustomizationSpecOrphan {
[CmdletBinding()]
param (
[int]
$DaysToKeep = 60
)
begin {
}
process {
$OSCustomizationSpecToRemove = Get-OSCustomizationSpec | Where-Object { $_.Name -like "AutoBuild-*" -and $_.LastUpdate -lt ((Get-Date).AddDays($DaysToKeep)) }
$OSCustomizationSpecToRemove | Remove-OSCustomizationSpec -Confirm:$false
}
end {
}
}
@@ -0,0 +1,76 @@
<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Set-ITDVMwareHostMaintenance {
[CmdletBinding()]
param (
[Parameter(ParameterSetName = 'Enclosure', Mandatory = $true)]
[string]
$EnclosureName,
[Parameter(ParameterSetName = 'Manual', Mandatory = $true)]
[string[]]
$VMHostName,
[ValidateSet('Maintenance', 'Online', 'Connected')]
[string]
$State
)
begin {
}
process {
switch ($PSCmdlet.ParameterSetName) {
'Enclosure' {
Write-Verbose "Setting all VMHosts in enclosure $EnclosureName to $State mode."
try {
$VMHostName = (Get-OVServer | Where-Object Name -like $EnclosureName -ErrorAction Stop).ServerName
}
catch {
Write-Error "Failed to retrieve enclosure $EnclosureName. Error: $_"
throw
}
}
'Manual' {
Write-Verbose "Setting specified VMHosts to $State mode."
}
}
switch ($State) {
'Maintenance' {
Write-Verbose "Setting VMHost $VMHostName to Maintenance mode."
try {
Get-VMHost -Name $VMHostName | Set-VMHost -State Maintenance -Confirm:$false -RunAsync
Disable-ITDVMwareVMHostFeature -Name $VMHostName -AlarmActions
}
catch {
Write-Error "Failed to set VMHost $VMHostName to Maintenance mode. Error: $_"
throw
}
}
'Online' {
Write-Verbose "Setting VMHost $VMHostName to Online mode."
Get-VMHost -Name $VMHostName | Set-VMHost -State Connected -Confirm:$false -RunAsync
Enable-ITDVMwareVMHostFeature -Name $VMHostName -AlarmActions
}
}
}
end {
}
}