Hi,I am trying to search if a server is present, it will show the progress (using write-progress activity in a loop) and tell me the time it took to fetch the details. Unable to compose the script to check the time takes to fetch the server record and progress, Please help/suggest.[quote]clear-hostfunction checkserver{ $Global:instance= Read-Host "Enter the SQL Service Instance Name [Dont use "" "" in the servername]:`n" write-host "You entered server name as:" $instance $serverObject = New-Object Microsoft.SqlServer.Management.Smo.Server($instance) $instance = $instance.toupper() $serverName = $serverObject.ComputerNamePhysicalNetBIOS $serverName = $serverName +"\"+$serverObject.InstanceName #$serverName IF ( $serverName -ne "\") { $sess = new-pssession $serverName Print $serverName invoke-command -session $sess -scriptblock {start-job -name Date1 -scriptblock {get-date}} write-host "Server:" "'$serverName'" "exist" -ForegroundColor Green Write-Progress -Activity "Working..." ` $done = invoke-command -session $sess -command {wait-job -name Date1} $done.count } ELSEIF ( $serverName -eq "\") { #$sess = new-pssession $serverName #invoke-command -session $sess -scriptblock {start-job -name Date1 -scriptblock {get-date}} write-host "Wrong Server name" -ForegroundColor Red #$done = invoke-command -session $sess -command {wait-job -name Date1} #$done.count } }[/quote]
↧