无法通过PowerShell通过logging的pathforms的SQL数据库检查共享空间

有谁能告诉我为什么我在这些代码上失败了?

1,我连接到数据库2,我从数据库中查询有用的信息(获取path)3,我查询了查询path下的空闲空间

这是我的代码:

######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() 

我相信我查询的path是有效的,因为我使用cmdtesting这个path。 但是我在这里失败了….错误日志是:

  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 

您的第一个错误发生:

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

networking位置无法到达

那么$var.droppath的价值是什么,在脚本之外是可以访问的呢?