I am creating a script to grab a user input share path or path and that will provide permission list of the provided path. Using Read-Host command-let I am asking user to provide input for number of paths he requires and thereby he/she needs to put on the paths one by one which will provide the ACL list. While doing this I'm getting issue where user inputs a wrong input such as if user provide an input which is not an integer or is a double value or its a string so it should go to my if condition and again he/she re-types the wrong number it would end up the script and would ask for re-run of the script.
I have tried below script however at line 4 I am totally stuck. here is the full code I have written. At line 3 when I input a value say 1.2 or any string value say Hello or any negative integer or 0 value, it should go to Line 4, else it should go to elseif which is line 36. Can someone help me out to fix this. I know I can do it in a shorter manner but something here is violating.
Clear-Host
Get-Date
$num_path= Read-Host "`n `n Enter number of paths"
if (($num_path -as [int]) -le 0 -or ($num_path -as [double]) -is [double])
{
Write-Host "Error: Value you have Entered is either less than or equal to 0 or not an interger or it is a String value.`nKindly enter correct value." -ForegroundColor Black -BackgroundColor Cyan
$New_num_path= Read-Host "`n `n Re-Enter number of paths"
if (($New_num_path -as [int]) -gt 0 -and !($New_num_path -as [double]) -is [double])
{
Write-Host "`n `n \\ServerName\FilePath `n `n Enter File Path in above format"
For($i=1; $i -le $New_num_path; $i++)
{
$paths= Read-Host "`n `nEnter File path no. $i " #Enter path with $ sign after drive name e.g E$\Applications
Write-Host "`n `n"
if (Test-Path -Path $paths)
{
foreach($path in $paths)
{
Get-Acl -Path $path | fl
}
}
Else
{
Write-Host "Error: Path '$paths' does not exist" -ForegroundColor Black -BackgroundColor Cyan
}
}
}
Else
{
Write-Host "Error: You have input wrong value. Kindly Re-run the script again." -ForegroundColor Black -BackgroundColor Cyan
}
}
Elseif(($num_path -as [int]) -gt 0)
{
Write-Host "`n `n \\ServerName\FilePath `n `n Enter File Path in above format"
For($i=1; $i -le $num_path; $i++)
{
$paths= Read-Host "`n `nEnter File path no. $i " #Enter path with $ sign after drive name e.g E$\Applications
Write-Host "`n `n"
if (Test-Path -Path $paths)
{
foreach($path in $paths)
{
Get-Acl -Path $path | fl
}
}
Else
{
Write-Host "Error: Path '$paths' does not exist" -ForegroundColor Black -BackgroundColor Cyan
}
}
}
Else
{
Write-Host "Error: You have input wrong value. Kindly Re-run the script again." -ForegroundColor Black -BackgroundColor Cyan
}
Write-Host "`n `n `n `t `t `t------------------------------------------------------THE END------------------------------------------------------`n"