Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Looping issue

$
0
0

Hi , I am learning PowerShell and newbie to PowerShell.

Can I get some help on below.

I created three files :

  1. Testfile
  2. BB-Thisisfile1223 ****?????
  3. CC-ThisisthelongestfileThisisthelongestfileThisisthelongestfileThisisthelongestfileThisisthelongestfileThisisthelongestfile

4. CC-ThisisthelongestfileThisisthelongestf &&& *** ileThisisthelongestfileThisisthelongestfileThisisthelongestfileThisisthelongestfile

5. Testfile 123 **** ??? ::

I am using below code , to get the output:

Ask from me:

I am getting output as expected for first 2 files as below

Output1 : File is not in defined format

Output2 : File has wild card operators

But even for 3rd file , I am getting below output , please help by correcting it.

Output3 : File has wild card operators

Also: I would like to get outputs exactly matching below:

File has wild card characters & more than 50 characters

File has Invalid format & has wild card operators

$q = "select * from table1"

$exec_q = Invoke-Sqlcmd -serverinstance abc -database new -Query $q $min = $exec_q | select name -ExpandProperty name foreach($n in $min){ if( $n -notmatch 'AA-'` -and $n -notmatch 'BB-'` -and $n -notmatch 'CC-'` ){ Write-Host "File is not in defined format" } Elseif( $n -match 'AA-'` -or $n -match 'BB-'` -or $n -match 'CC-'` -or $n -match @('[,/\:*?"<>&;]') ){ Write-Host "File has wild card operators" } Elseif( $n -match 'AA-'` -or $n -match 'BB-'` -or $n -match 'CC-'` -or $n.length -gt 70 ){ Write-Host "File has more than 50 characters" } Elseif( $n -match 'AA-'` -or $n -match 'BB-'` -or $n -match 'CC-'` -or $n.length -gt 70 ` -or $n -match @('[,/\:*?"<>&;]')){ Write-Host "File has wild card characters & more than 50 characters" } Elseif( $n -notmatch 'AA-'` -and $n -notmatch 'BB-'` -and $n -notmatch 'CC-'` -and $n.length -gt 70 ` -and $n -notmatch @('[,/\:*?"<>&;]')){ Write-Host "File has Invalid format & has wild card operators" }}



Best Regards,SQLBoy






Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>