Powershell script for configuration folders
Powershell script for configuration folders

PowerShell can be used to perform the task of configuring different folders by using the.config files.

First download the PS version of the Configure-ADConfigDrive cmdlet from the Microsoft Script Center.

Save the file to a folder on your computer and then double-click the file to open it.

The next step is to run the command below. Replace the following parameters as needed:

$serverName = "your_server_name"

$adminCredential = Get-Credential

$credsFile = ""

$folderPath = ""

Now that you have the necessary cmdlets, it's time to learn how to use them. You can run the cmdlet on different folders, which will copy the files from one folder to the other. The configuration files are located in the folder.

Once the cmdlet is run, it will ask you for a confirmation. You just need to select Yes and the process will be done.

Answer:

We have used Powershell script to create new folders and subfolders in Active directory. The scripts are run automatically at the scheduled time of the day. We have created Powershell scripts for following scenarios.

-Creating New folders based on the users group,

-Creating subfolders based on the users group,

-Creating subfolders based on the user ID,

-Creating subfolders based on the users profile path,

-Creating subfolders based on the users profile path,

-Adding users and groups to the existing groups in the active directory.

For example, if we have created a group in Active directory with name “Developers” then we can add new user to that group. This script will create a new folder named “developers” in the active directory.

The following is the powershell script for creating new folders based on the users group. You have to enter the username of the user whose information you want to get and the group name for which you want to create the folders.

$User = Get-ADUser -Identity "Enter the username of the user whose information you want to get" $Group = Get-ADGroup “Enter the group name for which you want to create the folders”

New-ADDirectory –Name “Enter the folder name” –Path “Enter the path where you want to create the folders” –Server “Enter the domain name where you want to create the folders” –Account “Enter the account of the user whose information you want to get” -Group “Enter the group name” –Attributes $group

1. I need to read the files from different configuration folder as below. C:\Program Files\Microsoft SQL Server\

2.ools\PowerShell\Ssconfig\Configurations\SQL2012_Express C:\Program Files\Microsoft SQL Server\

3.ools\PowerShell\Ssconfig\Configurations\SQL2014_Express C:\Program Files\Microsoft SQL Server\

4.ools\PowerShell\Ssconfig\Configurations\SQL2016_Express C:\Program Files\Microsoft SQL Server\

5.ools\PowerShell\Ssconfig\Configurations\SQL2017_Express A: #Get the file names of the config folders $ConfigPath = Get-ChildItem -Path "C:\Program Files\Microsoft SQL Server\

6.ools\PowerShell\Ssconfig\" | Select-Object -ExpandProperty FullName #Create an empty array to store the file names $FileNames = @() #Loop through each config folder foreach($Config in $ConfigPath) { #Create a new object for each file $fileObj = New-Object PSObject $fileObj | Add-Member -Type NoteProperty -Name 'FullName' -Value $Config.FullName #Loop through each file foreach($file in (Get-ChildItem $Config.FullName)){ #Append the name of the file to the array $fileNames += $file.Name } } #Get the name of the array $Array = $FileNames | Select-Object -ExpandProperty FullName #Add the array to the variable for the output $Output = $Array #Output the results $Output This script gets the files in the folders, and then stores them into an array that can be written to a variable for later use. The array will look like this: FullName --------- SQL2014_Express SQL2016_Express SQL2017_Express SQL2012_Express Question: Is there any way to speed up this query? No, because it's a basic query, just reading the data from the folder and appending to a variable for the output. I don't know how you are generating this list, but I assume that you are adding a lot of extra steps to get the data. It would be easier to make this into an array in the first place, or to generate a report in the first place. If this is being done in Excel, for example, then you could export to a CSV and import that into Power Query to do the work. Question: How to create a report from these files To create a report, use a report wizard, as follows: Select "New report" Click on the button "Add data source" Choose "From text file" Select the file you want to use, in this case I just choose "C:\Program Files\Microsoft SQL Server\

7.ools\PowerShell\Ssconfig\Configurations\SQL2012_Express" Click Next Click on "Next" Choose the report you want to use Finish. You should get something like this: Now, if you want to generate a report in Excel (or PowerQuery), you can use Excel's "Data > Get External Data..." and select "From another program" and choose your.csv file and it will generate the data for you in an Excel spreadsheet. Question: How to export data into SQL server from Excel? Use the following script (replace the values with yours): #Import the data into Excel as a table $Table = Import-Excel -Path "C:\Users\Public\Documents\ConfigFolder\SQL2012_Express.xlsx" -UseCells #Create a connection string using your server and database $ConnectionString = "Data Source=SERVER\DATABASE;Initial Catalog=DATABASE;User ID=USERID;Password=PASSWORD;" #Connect to the SQL Server #This will need to be run on a machine that is already configured to run the SQL Server #$Connection = New-Object System.Data.SqlClient.SqlConnection $Connection.ConnectionString = $ConnectionString $Connection.Open() #Run the SELECT query Select-Object * | Export-Excel -Path "C:\Users\Public\Documents\ConfigFolder\SQL2012_Express-Excel.xlsx" -UseCells -AutoSize $Connection.Close() Question: Is there any way to filter the file names? You can use the Where-Object cmdlet to filter the data: $ConfigPath = Get-ChildItem -Path "C:\Program Files\Microsoft SQL Server\

8.ools\PowerShell\Ssconfig\" | Select-Object -ExpandProperty FullName $FileNames = @() #Loop through each config folder foreach($Config in $ConfigPath) { #Create a new object for each file $fileObj

Leave a Reply

Your email address will not be published.