Found 463 Articles for PowerShell

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

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 C:\> $usbdev = gwmi win32_volume | where{$_.DriveType -eq '2'}The below commands will helpful to unallocated the USB from the system.PS C:\> $usbdev.DriveLetter = $null PS C:\> $usbdev.Put()OutputPath : \localhost\root\cimv2:Win32_Volume.DeviceID="\\?\Volume{6e4d6f1e-a8c2-11eb-9493-005056c00008}\" RelativePath : Win32_Volume.DeviceID="\\?\Volume{6e4d6f1e-a8c2-11eb-9493-005056c00008}\" Server : localhost NamespacePath : root\cimv2 ClassName : Win32_Volume IsClass : False IsInstance : True IsSingleton : FalseAnd ... Read More

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

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 InterfaceType or the DriveType.WMI commands, gwmi win32_diskdrive | where{$_.Interfacetype -eq "USB"}Alternatively, With the CIM commands, Get-CimInstance -ClassName Win32_DiskDrive | where{$_.InterfaceType -eq 'USB'}orGet-CimInstance -ClassName Win32_LogicalDisk | where{$_.DriveType -eq '2'}If there is no USB device connected to the system, there will be no output. To retrieve the USB disk on the remote ... Read More

How to get the Azure VM DNS name using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:46:01

1K+ Views

We can find the DNS name of the VM from the Azure Portal as shown below from the Azure VM Overview tab.This DNS setting is associated with the Public IP address. To retrieve the DNS settings we first need to retrieve the Public IP details. For this example, suppose we have the Azure VM TestMachine2k16 and we need to retrieve its DNS settings (Assuming you are connected to the proper Azure account and the subscription).$vm = Get-AzVM -VMName TestMachine2k16 $pubip = Get-AzPublicIpAddress -ResourceGroupName $vm.ResourceGroupName | where{$_.Id -match $vm.Name}$pubip variable has the attached Public IP properties. You can retrieve the DNS ... Read More

How to retrieve the Azure VM vNet name using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:45:09

1K+ Views

To retrieve the Azure Virtual Network (vNet) or subnet name, we need the first name of the network interface of the VM. Below is the command to retrieve the name of the network interface.$vm = Get-AzVM -VMName Testmachine2k16TestMachine2k16 is the Azure VM name. Assuming this VM has a single NIC attached.PS C:\> $nic = $vm.NetworkProfile.NetworkInterfaces PS C:\> $networkinterface = ($nic.id -split '/')[-1] PS C:\> $networkinterface testmachine2k16619So our NIC name is stored inside the $NetworkInterface variable.If you have the multiple NICs attached, then use the below command to retrieve the NIC details.$nics = $vm.NetworkProfile.NetworkInterfaces foreach($nic in $nics) {    ($nic.Id -split ... Read More

How to retrieve the Azure VM NIC name using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:44:45

1K+ Views

To retrieve the Azure VM NIC using PowerShell, we need to first get the VM details. For this example, we have the VM name “TestMachine2k16”. To retrieve the VM details use the Get-AzVM command but before that make sure you are connected to the Azure Account using PowerShell session.PS C:\> $vm = Get-AzVM -VMName Testmachine2k16VM NIC information is stored inside the NetworkProfile property.PS C:\> $vm.NetworkProfileThis will retrieve all the NICs attached to the VM. If there are multiple NICs then we need to store the nic information into the array and have to perform some string operation to get the ... Read More

How to install the MSI package using PowerShell DSC?

Chirag Nagrekar
Updated on 28-Apr-2021 13:43:36

1K+ Views

To install the MSI package using DSC, we need to use the DSC resource “Package”. Let see which properties are available for this resource.PS C:\> Get-DscResource -Name Package | Select -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ Name [string] True {} Path [string] True {} ProductId [string] True {} Arguments [string] False {} Credential [PSCredential] False {} DependsOn [string[]] False {} Ensure [string] False {Absent, Present} LogPath [string] False {} PsDscRunAsCredential [PSCredential] False {} ReturnCode [UInt32[]] False {}Name, Path, and ProductID parameters are mandatory for this DSC resource.The best way to retrieve the above details is ... Read More

How to install the MSI file using PowerShell?

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

22K+ 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 C:\Temp\7z1900-x64.msiThe above command will open the GUI to install the MSI file but we use PowerShell to avoid GUI interaction so we can add the argument to install the file.If you check which arguments are available to run the MSI file, use the below command.C:\Temp\7z1900-x64.msi /?It will popup box like ... Read More

How to get all the user profiles on the System using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:39:13

4K+ Views

All the new user profiles are created on the windows system at the path,'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\'To retrieve all the user profiles, we can usegci 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\' | ForEach-Object { $_.GetValue('ProfileImagePath') }ProfileImagePath property shows the location of the user profiles.Another way to retrieve the User Profile is using WMI.PS C:\> gwmi win32_userprofile |Select -ExpandProperty LocalPathOutputC:\Users\.NET v2.0 Classic C:\Users\.NET v4.5 Classic C:\Users\.NET v2.0 C:\Users\.NET v4.5 C:\Users\Classic .NET AppPool C:\Users\Administrator.AUTOMATIONLAB C:\Users\delta

How to get the IIS Application Pool Recycle settings using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:38:50

2K+ Views

To get the IIS application Pool to recycle settings using GUI, you need to check the Application pool advanced settings.To retrieve the above settings using PowerShell, we can use the Get-IISAppPool command with the specific application pool name. We have the application pool, DefaultAppPool and we need to retrieve its Recycling settings.PS C:\> (Get-IISAppPool -Name DefaultAppPool).RecyclingOutputBelow settings will be for the Periodic restart.PS C:\> (Get-IISAppPool -Name DefaultAppPool).Recycling.PeriodicRestartOutputMemory          : 0 PrivateMemory   : 102400 Requests        : 0 Schedule        : {add} Time            : 1.05:00:00 Attributes     ... Read More

How to get the IIS Application Pool failure Settings using PowerShell?

Chirag Nagrekar
Updated on 28-Apr-2021 13:38:08

554 Views

Using GUI from the IIS Manager, you can get the Application Pool Failure settings using App pool advanced settings from the Rapid-Fail Protection section as shown below.To retrieve the above settings using PowerShell, (Get-IISAppPool -Name DefaultAppPool).failureTo run the above command we need the IISAdministration module. You can retrieve the same settings using the WebAdministration module and using IIS PSDrive.(Get-ItemProperty IIS:\AppPools\DefaultAppPool\).failureTo retrieve the specific settings like Failure Interval or Maximum failures, use the below command.Failure Intervals, PS C:\> (Get-IISAppPool -Name DefaultAppPool).failure.rapidFailProtectionInterval Days              : 0 Hours             : 0 Minutes         ... Read More

Advertisements