How to set the ExecutionPolicy using Powershell

To set the ExecutionPolicy using Powershell, run Powershell as Administrator.
Type in Set-ExecutionPolicy followed by the ExecutionPolicy you wish to use.

  • Restricted: Restricted is the default execution policy. PowerShell scripts are not allowed to run.
  • All Signed: All Signed means thath if they are signed by a trusted publisher.
  • Remote Signed: Remote Signed means, any PowerShell scripts that have been locally created will be allowed to run.
  • Unrestricted: As the name implies, Unrestricted removes all restrictions from the execution policy.
  • Microsoft has disabled scripting by default to prevent malicious code from being executed.

    How to check if a number is a power of 2 in C# and VB.NET

    To check if a number is a power of 2 in C# and VB.NET you can use the following extension method.

    Sample C#

    public static bool IsPowerOfTwo(this ulong input)
    {
        return (input != 0) && ((input & (input - 1)) == 0);
    }
    

    Sample VB.NET

    <System.Runtime.CompilerServices.Extension> _
    Public Shared Function IsPowerOfTwo(input As ULong) As Boolean
    	Return (input <> 0) AndAlso ((input And (input - 1)) = 0)
    End Function
    

    As always, the extension method was added to out Fesslersoft.Extensions library @Github

    How to check if file or folder exists in Powershell

    To check if file or folder exists in Powershell you can use the following snippet.

    Sample Powershell

    for files use it like this

    if(test-path "C:\Users\Codesnippets\Desktop\Test.xml") 
    { 
    	echo "exists!" 
    } 
    else 
    { 
    	echo "not exists!" 
    }
    

    for folders/directories use it like this

    if(test-path "C:\Users\Codesnippets\Desktop") 
    { 
    	echo "exists!" 
    } 
    else 
    { 
    	echo "not exists!" 
    }