Chirag Nagrekar has Published 465 Articles

How to install the MSI file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 06-Nov-2023 03:36:26

21K+ Views

To install the MSI file with PowerShell, we can use cmdlet Start-Process.Let say we want to install the 7ZIP MSI file on the local computer and we have downloaded and stored the source file on the C:\temp location. Once we run the below command it will start the MSI installation.Start-Process ... Read More

How to add the user to the local Administrators group using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-Nov-2023 01:25:40

28K+ Views

To add the AD user or the local user to the local Administrators group using PowerShell, we need to use the Add-LocalGroupMember command.To add the local user to the local Administrators group, Add-LocalGroupMember -Group Administrators -Member TestUser -VerboseThe above command will add TestUser to the local Administrators group. You can ... Read More

How to count the total number of lines in the file in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 03-Nov-2023 21:24:10

25K+ Views

To count the total number of lines in the file in PowerShell, you first need to retrieve the content of the item using Get-Content cmdlet and need to use method Length() to retrieve the total number of lines. An example is shown below.Example(Get-Content D:\Temp\PowerShellcommands.csv).LengthOutputPS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellcommands.csv).Length 5727Read More

How to change Azure Subscription in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 03-Nov-2023 03:24:32

26K+ Views

To change the azure subscription using PowerShell, we can use the Select-AZSubscription command. When you use this command, you can use either the subscription ID, Subscription Name, or the Tenant ID.ExampleWith Subscription Name, Select-AzSubscription -SubscriptionName 'Visual Studio'With TenantID, Select-AzSubscription -Tenant 'XXXX-XXXXX-XXXXXXX-XXXX'With Subscription ID, Select-AzSubscription -SubscriptionId 'XXXX-XXXXX-XXXXXXX-XXXX'Sometimes on console messages will ... Read More

How to add/remove values in the array in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 03-Nov-2023 03:03:08

29K+ Views

An array is always a fixed size. To add value to the array, you need to create a new copy of the array and add value to it. To do so, you simply need to use += operator.For example, you have an existing array as given below.$array = 1, 2, ... Read More

How to get the System uptime with PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 01-Nov-2023 20:16:48

31K+ Views

To get the Windows System uptime with PowerShell, we can use the CIM Instance method with class name Win32_OperatingSystem. Once you use the mentioned class there is a property called LastBootupTime which shows the date when the computer is last rebooted.ExampleGet-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTimeOutputLastBootUpTime -------------- 9/29/2020 8:12:08 AMIf ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

32K+ 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 ... Read More

How to get the local Administrators group members using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 01-Nov-2023 14:03:11

34K+ Views

To get the local Administrators group members using PowerShell, you need to use the GetLocalGroupMember command. This command is available in PowerShell version 5.1 onwards and the module for it is Microsoft.PowerShell.LocalAccounts. This module is not available in the 32-bit PowerShell version but on a 64-bit system.In the below example, ... Read More

How to export output to excel in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 01-Nov-2023 02:04:11

38K+ Views

As of now, there is no built-in command like CSV (Export-CSV) to export output to the excel file but we can use the Out-File command to export data to excel or any other file format.Let’s use Out-File to export the output of the Get-Processes command to an excel file.Get-Process | ... Read More

How to delete registry Key using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 31-Oct-2023 22:00:48

43K+ Views

To delete the registry key using PowerShell, we can use the Remove-Item command. Remove-Item command removes the registry key from the path specified. For example, we have the registry key name NodeSoftware stored at the path HKLM, under the Software key.To delete the key we will use the below command.Remove-Item -Path HKLM:\SOFTWARE\NodeSoftware -Force -VerboseWe ... Read More

1 2 3 4 5 ... 47 Next
Advertisements