PowerShell Articles

Page 24 of 40

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 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 use the Set-Location command in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 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
Chirag Nagrekar
Updated on 02-Nov-2020 476 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
Chirag Nagrekar
Updated on 02-Nov-2020 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" }

Read More

How to add help in the PowerShell function?

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 422 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
Chirag Nagrekar
Updated on 02-Nov-2020 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 remove a member from the local group using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 7K+ Views

To remove a member from the local group using PowerShell, we can use the RemoveLocalGroupMember command. This command is available in the module Microsoft.PowerShell.LocalAccounts in and above PowerShell version 5.1.To use this command, we need to provide two parameter values. One is the -Group (Local Group Name) and the second is -Member (Name of the Member to remove). For example, Remove-LocalGroupMember -Group Administrators -Member TestUserThe above command will remove TestUser from the local group Administrators.To use the above command on the remote computer, we need to use Invoke-Command. For example, Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    Remove-LocalGroupMember -Group "Administrators" -Member ...

Read More

How to create a new local group using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 1K+ Views

To create a new local group on the local or the remote system using PowerShell, we can use the NewLocalGroup command. ExampleNew-LocalGroup -Name "TestGroup" -Description "Test Group"OutputName       Description ----       ----------- TestGroup Test GroupYou can verify it from the Computer Management GUI.To create the local group on the remote systems, you can use Invoke-Command. For example, Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    New-LocalGroup -Name 'TestGroup' -Description 'New Test Group' }The above command will create a New Local group named ‘TestGroup’ on the remote systems, Test1-Win2k12, and Test1-Win2k16.New-LocalGroup command is available in the module Microsoft.PowerShell.LocalAccounts which is part ...

Read More

How to get the list of local groups using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 02-Nov-2020 14K+ Views

To get the local groups on the windows system using PowerShell, you can use the Get-LocalGroup (Module: Microsoft.PowerShell.LocalAccounts) command. This command will list down all the groups on the particular system.If we check the properties of this command, it supports Name, Description, ObjectClass (user or group), PrincipalSource (ComputerName – Local or Remote), SID (Security Identifier).We will select them, PS C:\> Get-LocalGroup | Select Name, Objectclass, Principalsource, sid Name                                              ObjectClass PrincipalSource    SID ----           ...

Read More

How does PowerShell Pipeline work – Part 2?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Oct-2020 212 Views

In part-1 we have seen the PowerShell pipeline functionality using the ValueFromPipeline property. There is another cmdlet property known as ValueFromPipelineByPropertyName, which is also useful to know the PowerShell pipeline functionality.Like part-1 command, we can get this property name using the same Get-Command but the filter parameter we will use for the property is ValueFromPipelineByPropertyName.The below example is for the Stop-Service cmdlet.(Get-Command Stop-Service).ParameterSets.parameters | where{$_.ValueFromPipelineByPropertyName -eq 'True'} | Select Name, ParameterTypeOutputName ParameterType ---- ------------- Name System.String[]This means you can use Name property to stop the service. So here we will use Get-Service and its Name property to retrieve services and ...

Read More
Showing 231–240 of 391 articles
« Prev 1 22 23 24 25 26 40 Next »
Advertisements