mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-23 00:13:36 +01:00
Improved the scripts
This commit is contained in:
parent
0f4a7b11a6
commit
a2b271c2a9
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user