none
Get-ChildItem дополнительное условия RRS feed

  • Вопрос

  • Всем привет.

    Народ как создать несколько условий выборки для Get-ChildItem -Path "C:\test\*20241.cfm*,*20242.cfm"  | where {$_.Name -notmatch "~"} ругается...

    $user = 'Users'
    $pass = 'Pasword'
    $ftp = "ftp://test.com/"
    $cfm= Get-ChildItem -Path "C:\test\*20241.cfm*,*20242.cfm"  | where {$_.Name -notmatch "~"} 
    
    function Get-FtpDir ($url,$cred)
    {
        $request = [Net.WebRequest]::Create($url)
        $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
        $request.Credentials = $cred
        
        if ($request.GetResponse())
        {
            $response = $request.GetResponse()
            $reader = New-Object IO.StreamReader $response.GetResponseStream() 
            $reader.ReadToEnd(); $reader.Close(); $response.Close()
        }
    }
    $webclient = New-Object System.Net.WebClient
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
    $test = Get-FTPDir $ftp $webclient.Credentials
    if ($test -ne $null)
    {
    foreach($item in (dir $cfm "*.trc")){ 
        "Uploading $item..." 
        $uri = New-Object System.Uri($ftp+$item.Name)
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName) 
        Remove-Item -Path $cfm 
     } 
    }

    10 ноября 2019 г. 4:21

Ответы

  • Я инвалид, извините :)

    $user = 'Users'
    $pass = 'Pasword'
    $ftp = "ftp://test.com/"
    $cfm= Get-ChildItem -Path 'C:\test\*20241.cfm*','C:\test\*20242.cfm'  | where {$_.Name -notmatch "~"} 
    
    function Get-FtpDir ($url,$cred)
    {
        $request = [Net.WebRequest]::Create($url)
        $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
        $request.Credentials = $cred
        
        if ($request.GetResponse())
        {
            $response = $request.GetResponse()
            $reader = New-Object IO.StreamReader $response.GetResponseStream() 
            $reader.ReadToEnd(); $reader.Close(); $response.Close()
        }
    }
    $webclient = New-Object System.Net.WebClient
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
    $test = Get-FTPDir $ftp $webclient.Credentials
    if ($test -ne $null)
    {
    foreach($item in (dir $cfm "*.trc")){ 
        "Uploading $item..." 
        $uri = New-Object System.Uri($ftp+$item.Name)
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName) 
        Remove-Item -Path $cfm 
     } 
    }


    • Помечено в качестве ответа Vector BCOModerator 10 ноября 2019 г. 6:27
    10 ноября 2019 г. 4:39