Improved the scripts

This commit is contained in:
Markus Fleschutz 2021-02-10 20:37:37 +01:00
parent 0f4a7b11a6
commit a2b271c2a9
2 changed files with 21 additions and 22 deletions

View File

@ -2,28 +2,31 @@
<#
.SYNTAX ./check-mac-address.ps1 [<MAC>]
.DESCRIPTION checks the given MAC address for validity
MAC address like 00:00:00:00:00:00 or 00-00-00-00-00-00 or 000000000000
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
param($MAC = "")
param([string]$MAC)
# MAC-Address like 00:00:00:00:00:00 or 00-00-00-00-00-00 or 000000000000
$RegEx = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9A-Fa-f]{2}){6}$"
function IsMACAddressValid { param([string]$mac)
$RegEx = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9A-Fa-f]{2}){6}$"
if ($mac -match $RegEx) {
return $true
} else {
return $false
}
}
try {
if ($MAC -eq "" ) {
$MAC = read-host "Enter MAC address to validate"
}
if ($MAC -match $RegEx) {
write-output "MAC address $MAC is valid"
if (IsMACAddressValid $MAC) {
write-host -foregroundColor green "OK - MAC address $MAC is valid"
exit 0
} else {
write-output "MAC address $MAC is NOT valid"
write-warning "Invalid MAC address: $MAC"
exit 1
}
} catch {

View File

@ -6,16 +6,14 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param ([String]$XmlFilePath)
param($File = "")
try {
if ($XmlFilePath -eq "" ) {
$XmlFilePath = read-host "Enter path to XML file"
if ($File -eq "" ) {
$File = read-host "Enter path to XML file"
}
# Get the file
$XmlFile = Get-Item($XmlFilePath)
$XmlFile = Get-Item $File
# Keep count of how many errors there are in the XML file
$script:ErrorCount = 0
# Perform the XSD Validation
@ -27,14 +25,12 @@ try {
while ($Reader.Read()) { }
$Reader.Close()
# Verify the results of the XSD validation
if ($script:ErrorCount -gt 0) {
write-output "XML file is NOT valid"
write-warning "Invalid XML file"
exit 1
} else {
write-output "XML file is valid"
exit 0
}
}
write-host -foregroundColor green "OK - XML file is valid"
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1