Chirag Nagrekar has Published 465 Articles

How to validate the path with the PowerShell function parameter?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:42:17

1K+ Views

To validate the file or folder path inside the PowerShell function parameter, we need to use the ValidateScript command. Generally, we write the script as below to validate the path.function Validate-Path{    param(       [parameter(Mandatory)]       [String]$Path    )    if(Test-Path $Path) {Write-Output "Path is valid"} ... Read More

How to copy files of the specific extension using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:38:39

1K+ Views

To copy the files using the specific files extension using PowerShell, we can use the Copy-Item command.The below command will copy only the .ps1 files from the source to the destination.For example, PS C:\> Copy-Item -Path C:\Temp -Recurse -Filter *.ps1 -Destination C:\Temp1\ -VerboseIf the C:\Temp1 doesn't exist, it will create ... Read More

How to get the disabled local user accounts using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:37:12

1K+ Views

To get the disabled local user accounts using PowerShell on the local and the remote system, we can use the WMI or the CIM instance method with the Win32_UserAccount class and the Disabled property to filter the result.PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true}You can filter out the properties ... Read More

How to create a new local user in windows using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:20:05

3K+ Views

To create a new local user in the Windows operating system using PowerShell, we can use the New-LocalUser cmdlet. The below command will create the TestUser with no password.New-LocalUser -Name TestUser -NoPasswordOutputName Enabled Description ---- ------- ----------- TestUser TrueTestUser account has been enabled here. To provide the password for the ... Read More

How to install MSI file using batch file in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:17:21

3K+ Views

Let say we have one MSI file and we need to install the MSI file on the remote computers using PowerShell but that MSI file should be deployed with the Batch file and should be executed using PowerShell.In this example, we have a 7-zip MSI file and batch file we ... Read More

How to retrieve the Azure VM RAM and CPU size using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:08:03

4K+ Views

Azure VM RAM and CPU size depend on the hardware profile chosen for the VM. In this example, we will retrieve VM (TestMachine2k16) hardware profile and then we can find how much RAM or CPU is allocated to it.To get the Size of the Azure VM, PS C:\> $azvm = ... Read More

How to retrieve the Azure VM Subscription Name using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:07:25

1K+ Views

Once you are connected to the Azure Account, there are possibilities that the Get-AzVM will display the VMs from all the Azure Subscriptions.To find the specific Azure VM Subscription name, we will first retrieve the details of the VM using the Get-AzVM and it has an ID property that contains ... Read More

How to retrieve the Azure VM resource group using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:06:52

1K+ Views

To retrieve the azure VM resource group using PowerShell, we first need to retrieve the Azure VM details using Get-AZVm and then we can use its property called ResourceGroup.Before getting the details of the Azure VM, make sure that you are connected to the Azure Account using the Connect-AzAccount command.In ... Read More

How to eject the USB device from the system using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:05:55

4K+ Views

To eject the USB device from the system, we first need to get the USB device using PowerShell. WMI class Win32_Volume will help us to find the USB device.We know that all removal devices using the DriveType '2'. So we will filter out the USB device among the listed devices.PS ... Read More

How to check if the USB device is connected to the system using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-May-2021 12:01:49

3K+ Views

To retrieve the USB-connected devices using Powershell, we need to retrieve all the drives using the WMI object or CIM Instance and need to filter the win32_diskdrive class with the USB as shown below.So basically, USB devices and other removable devices have the drivetype '2'. You can search with the ... Read More

Advertisements