Found 2039 Articles for Microsoft Technologies

How to find a network adapter driver version using PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:31:58

8K+ Views

To find the network adapter driver version using PowerShell, we can use the Get-NetAdapter cmdlet. First, let look at how the network adapter driver version looks like from GUI.Get-NetAdapter will retrieve all the Physical and Virtual network adapters unless specified.This cmdlet has a property called DriverVersion, DriverDate, and DriverProvider. You can select it.ExampleGet-NetAdapter | Select Name, InterfaceDescription, DriverVersion, DriverDate, DriverProviderOutputName                    : Wi-Fi InterfaceDescription    : Intel(R) Wi-Fi 6 AX201 160MHz DriverVersion           : 21.80.2.1 DriverDate              : 2020-02-25 DriverProvider       ... Read More

Difference between single quote (‘) and double quote (“) in PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 06:49:46

5K+ Views

There is no such difference between the single quote (‘) and double quote(“) in PowerShell. It is similar to a programming language like Python. We generally use both quotes to print the statements.ExamplePS C:\> Write-Output 'This will be printed using Single quote' This will be printed using Single quote PS C:\> Write-Output "This will be printed using double quote" This will be printed using double quoteBut when we evaluate any expression or print variable it makes a clear difference.$date = Get-Date Write-Output 'Today date is : $date' Today date is : $date Write-Output "Today date is : $date" Today date ... Read More

How to use Push-Location and Pop-Location command in PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 11:12:22

3K+ Views

Push-Location command in PowerShell is used to push (add) the current location to the location stack (Last In First Out (LIFO) - queue) while the Pop-Location is to retrieve the last location from the stack.When the PowerShell console opens there are no locations set to the stack.PS C:\> Get-Location -Stack PS C:\>When you type the Push-Location command it performs two operations at a time. First, it saves the current location to the top of the stack, and second, it browse the path specified. If there is no path specified then it only moves the current location to the stack. For ... Read More

How to get the path of the currently executing script in PowerShell?

Chirag Nagrekar
Updated on 01-Nov-2023 14:43:24

45K+ Views

To get the full path of the script we need to use the $myInvocation command. This is an automatic variable and it is only invoked when the script or the function is executed.$MyInvocation.MyCommand.Path command is useful to get the full path of the script where it resides while $MyInvocation.MyCommand.Name is useful to get the name of the script. Example$mypath = $MyInvocation.MyCommand.Path Write-Output "Path of the script : $mypath"OutputPS C:\WINDOWS\system32> C:\Temp\TestPS.ps1 Path of the script : C:\Temp\TestPS.ps1Please note that we are running the above script from the System32 directory and the output path is C:\temp. To get the script directory, we can ... Read More

How to use the Set-Location command in PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 11:07:34

2K+ Views

Set-Location command in PowerShell is used to set the location of the drive from the current directory. The drive could be the local drive, folder path, shared path, registry, or any environmental variable.This command is very useful while writing the script because many times we need multiple files from the same folder and each time we need to mention the full path. This command allows us to set the path at the beginning of the script and then we can directly browse the path from the current directly.Example 1 − The below command sets the location from the C: to ... Read More

What is PowerShell Desired State Configuration?

Chirag Nagrekar
Updated on 02-Nov-2020 11:05:40

405 Views

Although DSC is a very large topic, we will quickly summarize it in this article with the needed concepts to what exactly it is and how we can implement it.PowerShell Desired State Configuration (DSC) is an Infrastructure automation tool and used for Infrastructure as a Code (Iaac). Besides, DSC can also be used as an Inventory management tool like to get the specific inventory from the servers if they exist or not. PowerShell and DSC both are different things. However, DSC can be implemented using PowerShell.PowerShell script uses Imperative model means we need to write the script how we will ... Read More

How to convert the hashtable to the JSON format using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 11:00:16

3K+ Views

To convert the hashtable to the JSON format we can use the ConvertTo-Json command. First, we have the following hashtable,Example$Body = [PSCustomObject]@{    AppName = 'StorageXIO'    AppID ='xo2ss-12233-2nn12'    License = 'valid' }To convert the hashtable to the JSON format,$Body | ConvertTo-JsonOnce you run the above command, properties are converted to the JSON format.Output{    "AppName": "StorageXIO",    "AppID": "xo2ss-12233-2nn12",    "License": "valid" }

How to add help in the PowerShell function?

Chirag Nagrekar
Updated on 02-Nov-2020 10:59:04

364 Views

When we write a program, people from a non-programming background often expect to get much possible help related to the program. When we write the function and we declare the parameters, people who are unaware of what kind of input the parameter need, generally search for the help first using the Get-Help command and then they find only the parameters but not the description of it. For example, function TestFunct{    param(       #16 Digit Application ID       [parameter(Mandatory=$true)]       [String]$AppID,       #Date in the Unix Format - 2020-10-31T17:12:10+0530       [String]$Date ... Read More

How to enable or disable local user on Windows OS using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:54:29

3K+ Views

To disable the local user on the windows OS using PowerShell, we can use the Disable-Localuser command provided by the local user name. In the below example, we are going to disable the local user called TestUser.Disable-LocalUser -Name TestUserIf we see the GUI, the user account is disabled.To enable the above user, we can use the Enable-LocalUser command.Enable-LocalUser -Name TestuserTo run the above command on the remote computer, we can use the Invoke-Command method. We need to make sure local user account exist on the remote computer.Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    Enable-Localuser -Name TestUser }Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{ ... Read More

How to delete the local group from the windows system using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:51:41

628 Views

To delete the local group from the windows system using PowerShell, you need to use the RemoveLocalGroup command as shown below.Remove-LocalGroup -Name TestGroupIn the above example, the local group name TestGroup will be removed from the local system. To remove the local group from the remote systems, we can use Invoke-Command as shown in the below example.Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock {Remove-LocalGroup -Name TestGroup}Remove-Localgroup command is supported from the PowerShell version 5.1 onwards and this command is a part of Microsoft.PowerShell.LocalAccounts module. If you have the PS version 5.1 or the local accounts module not available then you can use the ... Read More

Advertisements