Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Monday, September 6, 2021

how to add a list of empty folders to github in windows environment?

When we setup the project structure in the development. the Github have prevent us to push all empty folder to the GitHub Repository in remote server. we can use gitkeep utility in the Macs and Linux environmen to create gitkeep for those blank folder. we cannot gitkeep in the Windows environment. but there is a work around. we can use the powershell scripts to loop through all subfolders under the current project folder and add .gitkeep file in each empty folder. then we can upload those folders to the server.

here is the code to be execute in the windows PowerShell ISE, you should copy it to your windows PowerSehll ISE and replace {Your Current Project Folder path} with your own folder path

Get-ChildItem '{Your Current Project Folder path}' -Recurse -Directory | 

Where-Object {[System.IO.Directory]::GetFileSystemEntries($_.FullName).Count -eq 0} | 

ForEach-Object { New-Item ($_.FullName + "\.gitkeep") -ItemType file}




Tuesday, August 24, 2021

how to use Powershell to convert CSV file into Json format data?

 there is a built-in function in powershell cmdlet, which will allow us to convert the csv data into json format data.

first we should go to the folder where is the csv file stored. my csv file is found in this folder

C:\code\django\django-search-app\fixtures

PS C:\code\django\django-search-app\fixtures> ls

    Directory: C:\code\django\django-search-app\fixtures

Mode                 LastWriteTime         Length Name

----                 -------------         ------ ----

-a----         8/24/2021   1:26 PM         872488 books.csv

-a----         8/24/2021   1:35 PM         883612 books_title_author.csv


here is script to be run the in windows powershell and it should be executed inside the  folder

PS C:\code\django\django-search-app\fixtures> $topicsjson = import-csv .\books_title_author.csv | ConvertTo-Json

PS C:\code\django\django-search-app\fixtures> $topicsjson | Add-Content -Path "myData.json"

 $topicsjson = import-csv .\books_title_author.csv | ConvertTo-Json

 $topicsjson | Add-Content -Path "myData.json"

after the scripts is executed.

there should be a json file name myData.json within the file.

PS C:\code\django\django-search-app\fixtures> ls

    Directory: C:\code\django\django-search-app\fixtures

Mode                 LastWriteTime         Length Name

----                 -------------         ------ ----

-a----         8/24/2021   1:26 PM         872488 books.csv

-a----         8/24/2021   1:35 PM         883612 books_title_author.csv

-a----         8/24/2021   1:40 PM        2047343 myData.json





Friday, December 4, 2020

how to launch a program with Run as Administrator privilege in powershell?

 when you in the powershell window, you want to launch another app with run as administrator right. here is a way to go

ex: launch powershell with administrator privilege

start-process powershell  --Verb  runas

 run visual studio with administrator privilege

  start-process devenv.exe --Verb  runas



Friday, March 27, 2020

How to comment out multi-line in Windows Powershell?

if we want to comment out multiple line in the Powershell ISE. there is a shotcut to do so.

comment out multi-line:

use "ALT + SHIFT" to move down to the end of the last line that you want to comment out,

then use "SHIFT + #" to add # to all lines being selected.

 uncomment multi-line:

use "ALT + SHIFT" to move down to the end of the last line that you want to uncomment,

then press Delete button to undo all the comment out code.

having more fun with PowerShell !


Friday, October 31, 2014

How to use PowerShell to uninstall a feature by GUID in SharePoint 2013

 it is quite handy and quick to uninstall a Farm Solution Feature in sharePoint 2013


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

#Get-SPFeature  to find the feature that we need to uninstall from the server
Get-SPFeature -Limit ALL | Where-Object {$_.DisplayName -like "*Wing*"}

DisplayName                    Id                                                       CompatibilityLevel Scope                        
-----------                    --                                       ------------------   -----                        
WingTipToys_WingTipsContact... fe80d321-83a0-4d7d-92ce-e7b84e6ef428     15 

# uninstall the feature using the GUID id
                                              
Uninstall-SPFeature -id "fe80d321-83a0-4d7d-92ce-e7b84e6ef428"

Monday, October 27, 2014

the beauty of Sharepoint 2013 Deveoper Dashboard

Microsoft introduced the developer Dashboard in SharePoint 2010, it is embedded in the page. which will help the developer trouble shooting the issue on the SharePoint page. the Developer DashBoard still is available in the SharePoint 2013 but with great improvement. The Developer DashBoard will be popup into
a separated page.

here is the screen of the SharePoint 2013 Developer DashBoard





Unfortunately it had been turn off by default. we must use the powershell script to turn it on


$DevDashboardSettings = [Microsoft.SharePoint.Administration.SPWebService]:: ` ContentService.DeveloperDashboardSettings
$DevDashboardSettings.DisplayLevel = 'On'
$DevDashboardsettings.Update()

after you execute the powershell script, then lauch the sharepoint web site, you should be able to spot an icon to launch the Developer DashBoard (I already circled the icon in red)












Thursday, October 23, 2014

Very Handy PowerShell Command

I recently get involved in the development with Power Shell.  I found that some of power shell  command is

quite helpful for debug purpose.


Read-Host  will keep the power shell console window open when you right the power shell script and execute it by launching the Power Shell window. we can see the outcome of the script execution.


pause will  keep power shell console window open when you run the ps by using the windows batch file.


Set-Location will change the folder where the script stored.

-C put this in front of the comparison operator will solve the power shell case intensive issue in string comparison

(`) will add a line break to chop a long script into multiple lines






Friday, June 22, 2012

powershell script to configure the AD Domain Control for win Server 2012

you can run this script in powershell windows to configure the new AD domain
control automatically when you add a new AD domain controller to the server farm. 

#
# Windows PowerShell script for AD DS Deployment
#

Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012" `
-DomainName "WINServer2012.Local" `
-DomainNetbiosName "WINSERVER2012" `
-ForestMode "Win2012" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true