tomeaton12 (5/18/2012)
Hello,I am new to Powershell and I have been asked to get the SQL Server Database data path and insert this veriable into a script to gather permissions from the folders and inserts them into a csv file. I have insert my code so far below
Any help would be much appriciated.
Param (
[STRING] $SQLSERVER = "Server, port"
)
$permsLogFile = "C:\Users\Output.txt"
Write-Output "Start of the script" > $permsLogFile
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$SQLSERVER;Database=master;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "SELECT SUBSTRING(filename,1,CHARINDEX('A\master.',filename)) from master..sysdatabases WHERE name = 'master'"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$networkPath = $DataSet.Tables[0]
$subFolders = Get-ChildItem -Name $networkPath
foreach ($Folder in $subFolders){
$cmd = "cacls $networkPath\$Folder"
Write-Output "Running Commamnd:" $networkPath >> $permsLogFile
Invoke-Expression $cmd | Write-Output >> $permsLogFile}
$SqlConnection.Close()
So does it work or is it giving errors??? If it's giving errors, what are they???
--Jeff Moden
Change is inevitable... Change for the better is not.