Skip to main content

Posts

Showing posts matching the search for Powershell

Enable Trace on Dynamcis 365 on premise using PowerShell

Enable trace settings through Windows PowerShell Note These changes made in Windows PowerShell do not update the Registry. These changes update the DeploymentProperties and ServerSettingsProperties tables in the MSCRM_CONFIG database. Register the cmdlets 1.      Log in to the administrator account on your Microsoft Dynamics CRM server. 2.      In a Windows PowerShell window, type the following command: Add-PSSnapin Microsoft.Crm.PowerShell To obtain a list of the current settings, type the following command: Get-CrmSetting TraceSettings Set the trace settings 1.      Type the following command: $setting = Get-CrmSetting TraceSettings 2.      Type the following command to enable tracing: $setting.Enabled=$True 3.      Type the following command to set the trace settings: Set-CrmSetting $setting 4.      Type the following command...

Quick Trip: Rename Current branch in Git

I love to use Powershell and post-git module for day to day work with git. Sometimes, I have to rename my branches and I have this quick way to do to it. I love to write shortcuts in PowerShell's Profile to save time. Add this function in Powershell Profile.ps1: function RenameLocalBranch { param ( $ NewName ) $ currentBranch = git rev - parse -- abbrev - ref HEAD git branch - m $ NewName git push origin : $ currentBranch $ NewName git push origin - u $ NewName } save the profile.ps1 and open a new go to repo path call the function and give it a new branch name, it should update local and remote branch for you. here is the successful output: C:\Repos\proj [ name1 ≡ ] > RenameLocalBranch name2 Total 0 ( delta 0 ) , reused 0 ( delta 0 ) To https: // xxxxxxxxx.visualstudio.com / _git / xxxxxxxxxx - [ deleted ] name1 * [ new branch ] name2 -> name2 Everything up - to - date Branch ' name2 ...

PowerShell: Get Strong Random Password

function GetRandomPassword { $ strSrc = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$^&(){}[],. ' $ max = $ strSrc.Length $ strPass = '' for ($ i = 0 ; $ i -lt 20 ; $ i += 1 ) { $ index = Get-Random - Minimum 0 - Maximum $ max $ c = $ strSrc [$ index ] $ strPass += $ c } return $ strPass } create the above function in your powershell profile and you can generate random password at anytime. Happy Coding!!

Check and Create a Node in XML, if it does not existing using PowerShell

Here is a quick code snippet to Add a Node in XML from from the XPath, the following PowerShell function will search for the node hierarchy, if it does not exist then it will create it. function   CheckForXMLNode  {      param  (          $File , # File Path of XML to search the node          $NodePath     )      $nodes  =  $NodePath  -split  "/"      $path  =  "//Configuration"      # My Sample Node Path is like this # //Configuration/Farm/CustomParent/CustomChild      foreach  ( $node   in   $nodes ) {          if  ( ( $node  -ne  "" ) -and ( $node  -ne  "Configuration" ) ) {   ...

Register/Deregister ADO agents using PowerShell

 here is the script you can use to register/deregister ADO agents PARAM( [int] $NoofAgents, [string] $vsts_url = "https://dev.azure.com/name", [string] $vsts_pat, [string] $svcUserName = "domain\user", [string] $svcPassword, [string] $agentAction ) $agent_pool = 'Poolname'; $ErrorActionPreference="Stop"; If(-NOT (Test-Path $env:SystemDrive\'agents')) {mkdir $env:SystemDrive\'agents'}; Cd $env:SystemDrive\'agents'; if($agentAction -eq "register"){ Write-Host "Download Agent Zip from ADO..." -NoNewline $agentZip="$PWD\agent.zip"; $DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy; $securityProtocol=@(); $securityProtocol+=[Net.ServicePointManager]::SecurityProtocol; $securityProtocol+=[Net.SecurityProtocolType]::Tls12; [Net.ServicePointManager]::SecurityProtocol=$securityProtocol; $WebClient=New-Object N...

Save User Credentials in Secured File

If you want to save credentials in a file and later want to use it in a script here is the trick. You can use  PowerShell's built-in XML serialization (Clixml): #1. Get The Credentials $cred = Get-Credentails #2. Save the Credentails as a file $cred | Export-CliXml "MyFileName.xml" #3. Read the Credentials back from file $myCred = Import-CliXml "<Path>/MyFileName.xml"

Azure Locks: A Comprehensive Guide

  What are Azure Locks? Azure Locks are a powerful tool that allows you to restrict changes to Azure resources. By applying a lock to a resource, you can prevent unauthorized modifications, ensuring the integrity and security of your Azure environment. Types of Azure Locks There are two main types of Azure Locks: ReadOnly: This lock prevents any modifications to the resource, including updates, deletions, or changes to its properties. CanNotDelete: This lock prevents the deletion of the resource, but allows updates to its properties. Advantages of Using Azure Locks Enhanced Security: Prevent unauthorized changes to critical resources. Compliance Adherence: Ensure compliance with regulatory requirements or internal policies. Resource Protection: Protect resources from accidental deletions or modifications. Change Management: Implement a controlled process for making changes to resources. Common Use Cases for Azure Locks Protecting critical resources: Lock down highly...

PowerShell: Get Actual Error

I was having hard time to find the reason why I was not able to find a custom method in a .Net DLL. Find your Assembly: PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts > [appdomain]::currentdomain . getassemblies() | Where - Object FullName - Match "MyAssembly" GAC Version Location --- ------- -------- False v4 . 0.30319 C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts\Tools\MyAssembly . dll PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts & gt; $ a = [appdomain]::currentdomain . getassemblies() | Where - Object FullName - Match "MyAssembly" PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts & gt; $ a GAC Version Location --- ------- -------- False v4 . 0.30319 C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts\Tools\MyAssembly . dll When I was trying to get the Types in the assembly, I was getting the exception: PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts > ...