Found 463 Articles for PowerShell

How to Set environment variables using PowerShell?

Chirag Nagrekar
Updated on 29-Aug-2023 07:24:55

217K+ Views

To set the environmental variable using PowerShell you need to use the assignment operator (=). If the variable already exists then you can use the += operator to append the value, otherwise, a new environment variable will be created.For example, there is no AZURE_RESOURCE_GROUP environment variable that exists in the system. We can create it as below.$env:AZURE_RESOURCE_GROUP = 'MyTestResourceGroup'Now when you check the environment variables in the system, you will get the above variable name.PS C:\Windows\system32> dir env: Name                            Value ----             ... Read More

How to get environment variable value using PowerShell?

Chirag Nagrekar
Updated on 31-Oct-2023 13:31:58

71K+ Views

Environment variables are an essential part of the Operating System. They store various information like the path of the system files and folders, the number of processors system running, current user details, and more. Processes and programs utilize these environment variables to retrieve the data for their execution.Environment variables in PowerShell are stored as PS drive (Env: ). To retrieve all the environment variables stored in the OS you can use the below command.Get-ChildItem -Path Env:Name                        Value ----                       ... Read More

How to disable windows firewall profiles using PowerShell?

Chirag Nagrekar
Updated on 28-Sep-2020 08:37:52

961 Views

There are 3 types of profiles that firewall supports. a) Domain b) Public and c) Private profile. You can check the same settings using the GUI in the Windows Firewall Advanced Security settings window as shown below.You can check the above settings using the Get-NetFirewallProfile command.Get-NetFirewallProfile | Select Name, Enabled Name Enabled ---- ------- Domain True Private True Public TrueTo turn off or disable the above profiles using PowerShell, you need to use the command Set-NetFirewallProfile.To disable the specific profile, use -Profile parameter. You can pass 3 different profile ... Read More

How to get windows firewall profile settings using PowerShell?

Chirag Nagrekar
Updated on 28-Sep-2020 08:28:11

2K+ Views

Recent windows client and server operating systems like Windows 10, Windows Server 2008 onwards, supports advanced firewall versions and they have mainly 3 profiles.DomainPublicPrivate profile.To get the setting using GUI, you need to search in the box Windows Firewall with Advanced Security or Windows Defender Firewall with Advanced Security. Then you can see in the console that 3 available profiles.The above same settings can be viewed with the PowerShell Get-NetFirewallProfile command.PS C:\> Get-NetFirewallProfile Name : Domain Enabled : True DefaultInboundAction : NotConfigured DefaultOutboundAction : NotConfigured AllowInboundRules : NotConfigured AllowLocalFirewallRules : NotConfigured AllowLocalIPsecRules : NotConfigured AllowUserApps : NotConfigured AllowUserPorts : NotConfigured ... Read More

How to check if remote ports are open using PowerShell?

Chirag Nagrekar
Updated on 28-Sep-2020 08:21:45

6K+ Views

Earlier days we were using telnet clients to check the remote port connectivity, in fact, we are still using it with cmd and PowerShell but this feature is not by default installed in OS and some companies have restrictions on installing new features including telnet.We can leverage PowerShell to test remote port connectivity without installing telnet and with the use of the Test-NetConnection command. This command is also very useful for other diagnostics but we are focusing here for the remote port check.To check if the remote port is open or not we can use the Test-NetConnection command and it ... Read More

How to Copy NTFS permissions using PowerShell?

Chirag Nagrekar
Updated on 28-Sep-2020 08:17:32

8K+ Views

To change, add or remove security permissions on the files or folder using PowerShell you can use the Set-Acl command. The best way to set the permission is to copy the permissions from another file or folder if you need the same permissions on the destination path.For example, I want the same folder permissions of the source C:\Shared\ to the destination folder path c:\shared1 path. You can use any destination path, it could be the remote shared UNC path.See the difference in the above security permissions, the Shared named folder has one additional permission assigned (LABDOMAIN\Delta). We will copy the ... Read More

How to view folder NTFS permission with PowerShell?

Chirag Nagrekar
Updated on 28-Sep-2020 08:10:15

3K+ Views

To view the NTFS permission with PowerShell, we use the Get-ACL command. This command is supported in PowerShell version 5.1 or later. Generally how we get the security permission of the folder in the Windows OS using GUI, To get the same permissions shown above using PowerShell, use the below command.Get-Acl C:\SharedPS C:\> Get-Acl C:\Shared Directory: C:\ Path      Owner     Access ----      -----     ------ Shared BUILTIN\Administrators NT AUTHORITY\SYSTEM Allow FullControl...You can compare the first image with the above output. You can compare the Owner of the folder and it ... Read More

What is the use of the Get-Error cmdlet in PowerShell?

Chirag Nagrekar
Updated on 19-Sep-2020 13:54:50

634 Views

Get-Error cmdlet was introduced in PowerShell v7. It displays the most recent error messages from the current session.When you check the get member of this command, its output is in the form of PSExtendedError so whatever the output is produced by this command is in a detailed manner and so this command is very helpful in troubleshooting error messages.PS C:\> Get-Error | gm TypeName: System.Management.Automation.ErrorRecord#PSExtendedErrorWe will write one command in the PowerShell console which is ultimately generate an error.PS C:\> Get-ChildItem c:otexist Get-ChildItem: Cannot find path 'C:otexist' because it does not exist.The above directory does not exist. Let’s get a ... Read More

What is the use of $ErrorView in PowerShell?

Chirag Nagrekar
Updated on 19-Sep-2020 13:43:29

1K+ Views

$Errorview variable determines the display format of the error message in PowerShell. Before PowerShell 7 there were mainly two views, Normal View (Default view)Category ViewWith PowerShell version 7, one new additional error view category is included and now there are 3 $ErrorView categories for version 7.Concise View (Default)Normal ViewCategory ViewWe will understand each view one by one.A ) Normal ViewIt is the default view before PowerShell version 7 and it produces the detailed multiline errors and bit noisy. It includes the exception name, category, line number of the error, etc.$ErrorView = 'NormalView' Get-ChildItem C:\NoDirectoryOutputGet-ChildItem : Cannot find path 'C:\NoDirectory' because ... Read More

Which are the new Null Operators introduced in PowerShell version 7?

Chirag Nagrekar
Updated on 19-Sep-2020 13:36:24

160 Views

PowerShell version 7 has introduced a few new null operators. They are as below.Null-Coalescing operator - ??Null Conditional Assignment Operators - ??=Null Conditional member access operators - ?. and ?[]a. Null-Coalescing operator - ??Null Coalescing operator ??evaluates the left-hand side condition or operand and if it is null then evaluates the right-hand side operand otherwise provides the value of the left-hand side operand.For example, Without the Null-Coalescing operator, we would have written a script like as shown below, $Name = $null if($Name -eq $null){"Name is Null"} Else {"PowerShell"}The above same condition can be written with the ?? operator.$name = $null ... Read More

Advertisements