Falha ao verificar o espaço de compartilhamento via banco de dados sql de formulário de caminho gravado pelo powershell

1

Alguém poderia me dizer por que eu falhei nesses códigos?

1, conecto-me ao banco de dados 2, eu consultar informações úteis do banco de dados (get path) 3, verifiquei o espaço livre sob o caminho consultado

Aqui estão os meus códigos:

######connect to windows authentication local database################################

$connection= new-object system.data.sqlclient.sqlconnection #Set new object to connect to sql database

$Connection.ConnectionString ="server=.;database=sharespace;trusted_connection=True" # Connectiongstring setting for local machine database with window authentication

Write-host "connection information:"

$connection #List connection information

Write-host "connect to database successful."

$connection.open() #Connecting successful

#########query drop paths############################################################

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand #setting object to use sql commands

$SqlQuery = "select Droppath from sharespace" #setting query "get drop paths"

$SqlCmd.CommandText = $SqlQuery # get query

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter #

$SqlAdapter.SelectCommand = $SqlCmd #

$SqlCmd.Connection = $Connection

$DataSet = New-Object System.Data.DataSet

$SqlAdapter.Fill($DataSet) 

#$Connection.Close()

$DataSet.Tables[0].rows[1]
#############check free space form drop paths###########################################


$var=$dataset.tables[0].rows[1]  #
#$var.system.data.datarow

$var.droppath

$map = new-Object -com wscript.Network 

$map.mapNetworkDrive("v:",$($var.droppath))

$fso = new-Object -com Scripting.FileSystemObject

$do = $fso.getdrive("v:")

$do.AvailableSpace

$do.TotalSize

#$var|get-member

$map.RemoveNetworkDrive("v:")

$Connection.Close()

Tenho certeza de que o caminho que consultei é válido, pois testei esse caminho usando o cmd. Mas eu falhei aqui .... logs de erro são:

  Exception calling "MapNetworkDrive" with "2" argument(s): "The network location     cannot be reached. For information about network troubleshooting, see Windows Help."
  At D:\checkfreespace.ps1:47 char:21
  + $map.mapNetworkDrive <<<< ("v:",$($var.droppath))
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : ComMethodTargetInvocation

  Exception calling "GetDrive" with "1" argument(s): "Exception from HRESULT: 0x800A0044 (CTL_E_DEVICEUNAVAILABLE)"
  At D:\checkfreespace.ps1:51 char:20
  + $do = $fso.getdrive <<<< ("v:")
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : ComMethodTargetInvocation

  Exception calling "RemoveNetworkDrive" with "1" argument(s): "This network connection does not exist."
  At D:\checkfreespace.ps1:59 char:24
  + $map.RemoveNetworkDrive <<<< ("v:")
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : ComMethodTargetInvocation
    
por pansal 08.07.2011 / 06:47

1 resposta

1

Seu primeiro erro ocorre:

$map.mapNetworkDrive <<<< ("v:",$($var.droppath))

The network location cannot be reached

Então qual é o valor de $var.droppath e é acessível fora desse script?

    
por 08.07.2011 / 09:38