码迷,mamicode.com
首页 > 系统相关 > 详细

Powershell-常用脚本

时间:2019-05-06 14:42:39      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:err   path   ror   rect   sockets   soc   director   string   dir   

function Test-Port
{
    Param([string]$ComputerName,$port = 5985,$timeout = 1000)
    try
    {
        $tcpclient = New-Object -TypeName system.Net.Sockets.TcpClient
        $iar = $tcpclient.BeginConnect($ComputerName,$port,$null,$null)
        $wait = $iar.AsyncWaitHandle.WaitOne($timeout,$false)
        if(!$wait)
        {
            $tcpclient.Close()
            return $false
        }
        else
        {
            # Close the connection and report the error if there is one
             
            $null = $tcpclient.EndConnect($iar)
            $tcpclient.Close()
            return $true
        }
    }
    catch
    {
        $false
    }
}

function copy-dir([string]$src, [string]$des)
    {   
        get-childitem $src -recurse -directory | foreach-object { $tmp = $_.fullname;$tmp = $tmp.substring( $src.length, $tmp.length - $src.length ); if( -not (test-path $des$tmp) ) { new-item -path $des$tmp -type Directory -force } }    
    }

 

Powershell-常用脚本

标签:err   path   ror   rect   sockets   soc   director   string   dir   

原文地址:https://www.cnblogs.com/JinweiChang/p/10819154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!