Tuesday, October 29, 2019

Remove special characters from the Folders and files using PowerShell script

#To remove the special characters from the Drive. Use the following PowerShell script



$Folder = "D:\TCA"
$Items = Get-ChildItem -Path $Folder -Recurse

#Add special characters that need to be renamed or removed
$UnsupportedChars = '[#%]'

foreach ($item in $items){
    filter Matches($UnsupportedChars){
    $item.Name | Select-String -AllMatches $UnsupportedChars |
    Select-Object -ExpandProperty Matches
    Select-Object -ExpandProperty Values
    }

    $newFileName = $item.Name
    Matches $UnsupportedChars | ForEach-Object {
        Write-Host "$($item.FullName) has the illegal character $($_.Value)" -ForegroundColor Red
        #These characters may be used on the file system but not SharePoint
        if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
        if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
     }
     if (($newFileName -ne $item.Name)){
        Rename-Item $item.FullName -NewName ($newFileName)
        Write-Host "$($item.Name) has been changed to $newFileName" -ForegroundColor Green
     }
}

Wednesday, January 30, 2019

Date format issue for some users

Scenario #1:
The RDS server is migrated to different region DC.

Issue:
When existing users access the MS access as remote app, they get date format issue.

Error message:
Your system is configured for American date format mm/dd/yyyy. Please change the regional settings to Australia and try again

Scenario #2:
Date format not showing correctly in server for some users when they remotely login to the server

Issue: Some users still see the date format as MM/dd/yyyy even though it is set to dd/MM/yyyy.

Troubleshooting: Since the issue is occurring only for some users, it's more related to user profile

Resolution: Delete the stored user profile from the server for existing users. Since the existing user profile are stored and that regional details are displayed based on user profile stored. Once the existing user profiles are delete, a new user profile is created and saved when user logins in again.

Steps to delete the user profile

  1. Run > sysdm.cpl to open System Properties window
  2. Click on Advanced tab
  3. Click on Settings button under User Profiles section
  4. Select the user profile with issue and click Delete User Profile

Note: If Delete button is grayed out/disabled, make sure that user does not have any active/disconnected session. You can check this in Task Manager > Users. Log off the user and try to delete again.

Monday, July 23, 2018

Command to get windows services and windows features

Following are the PowerShell script and Command to get the Windows Servers and Windows Roles and features list

Get Services using PowerShell

Import-Module Servermanager
Get-Service | Export-Csv -path "H:\SharePoint\Services_Features\MYUATSQL_services.csv"
Get-WindowsFeature | Export-Clixml "H:\SharePoint\Services_Features Report\MYUATSQL_features.xml"

Get Service logons details using command prompt.

wmic service get name,startname> "H:\SharePoint\Services_Features\MYUATSQL_serviceLogons.csv"

Wednesday, April 18, 2018

Android close app when back button is pressed using Xamarin c#

Requirement: Close the app when back button is pressed using C# in Xamarin.

Scenario: We may need to close the app when we press back button from app's home page

Code:
Use the following line of code in OnBackPressed event.

public class MainActivity : Activity
{
....
....
...
...

   public override void OnBackPressed()
   {
                base.OnBackPressed();
                var intent = new Intent(this, typeof(MainActivity)); 
                base.Finish();
                System.Environment.Exit(0);
    }
}


Thursday, January 11, 2018

Render JSON data in HTML using ReactJS

Following code is to render JSON data in HTML using ReactJS

HTML Code

<div id="root"></div>

JS Code
Load latest react scripts files.
Following script files were used in this example.
Add following code in to your script.
//Your JSON Data
var empdata = {
 content: {
     employee: [
       {
         name: "Joe",
         Age: 30,
         id : 1007
       },
       {
         name: "Bill",
         Age: 35,
         id : 1008
       }
     ]
  }
};
//Create Class
var Employees = React.createClass({
render: function() {
  //To retrieve keys from data.content
  var keys = Object.keys(empdata.content);
  //iterate through the keys to get the underlying values
  var allEmps = keys.map((t) => empdata.content[t].map((e) => ({e.id}-{e.name}-{e.Age})));
return ({allEmps})
}
});

//Render data to HTML
ReactDOM.render(, document.getElementById("root"));



Friday, March 23, 2012

Color is not showing properly in print out

Issue: Colors in the Web Page is not getting exact color when printed out.

Solution: Click File menu in the browser > select Page Setup > check Print Background Colors and Images. > Click OK

Saturday, July 2, 2011

Get first letter of each word in a sentence


 private string GetAcronym(string strSiteName)
        {
            string shortName = string.Empty;
            string[] txtArray = strSiteName.Split(' ');
     
       //if site name is a single word, get the first three characters of the site name
                if (txtArray.Length == 1)
                {
                    return strSiteName.Substring(0, 3);
                }

                //Get the first letter of each word in the site name
                foreach (string word in txtArray)
                {
                    shortName += word.Substring(0, 1);
                }
                return shortName;
            }