Found 463 Articles for PowerShell

How to get the Azure VM available sizes using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 09:31:05

547 Views

To get the Azure VM sizes using PowerShell, we can use the Get-AzVmSize command.To get all the supported Azure VM sizes as per location, use the below command.PS C:\> Get-AzVMSize -Location EastusOutputTo get available and supported size for the existing virtual machine, use the below command.Get-AzVMSize -ResourceGroupName ResourceGroup1 -VMName TestVM

How to get the Application security groups of the Azure VM using PowerShell?

Chirag Nagrekar
Updated on 31-Aug-2021 09:40:48

421 Views

To get the Application security groups of the Azure VM using PowerShell, we need to first get the Network Interface of the Azure VM.The below command will retrieve the NIC name of the Azure VM.PS C:\> $vm = Get-AzVM -Name TestVM $nic = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]Once we have the NIC name, we can use the Get-AzNetworkInterface command to retrieve the NIC information and the Security group.The below command will retrieve the application security group names using PowerShell.PS C:\> $nicsettings = Get-AzNetworkInterface -Name $nic $nicsettings.IpConfigurations.ApplicationSecurityGroups

How to get the load balancers connected to the Azure VM using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 09:52:41

413 Views

To get the load balancers attached to the Azure VM using PowerShell, we first need to retrieve the Azure VM network settings. For example, we have an Azure VM name “TestVM” and we willPS C:\> $vm = Get-AzVM -Name TestVM $nic = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]Once we have the network interface name, we need to retrieve the load balancer settings, and to get the Load Balancer settings we need to use the Get-AzNetworkInterface command.PS C:\> $nicsettings = Get-AzNetworkInterface -Name $nicThe below command will retrieve the load balancer name.(($nicsettings.IpConfigurations.LoadBalancerBackendAddressPools.id).Split('/'))[-3]To get the Load Balancer backend pool name, use the below command.(($nicsettings.IpConfigurations.LoadBalancerBackendAddressPools.id).Split('/'))[-1]Overall Script −$vm = Get-AzVM ... Read More

How to get the Azure VM virtual Network and the Subnet name using PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 09:51:41

1K+ Views

To retrieve the Azure VM virtual network and subnet name, we first need to retrieve the AzureVM NIC information. To get the Azure VM NIC information, we need to use the Get-AzVM command, and then we can use the NetworkProfile property to retrieve the NIC name as shown below.PS C:\> $vm = Get-AzVM -Name TestVM $vmnic = ($vm.NetworkProfile.NetworkInterfaces.id).Split('/')[-1]Once we have the NIC name stored from the above command in the $vmnic variable, we can retrieve the NIC information using the Get-AzNetworkInterface command as shown below.$vmnicinfo = Get-AzNetworkInterface -Name $vmnicTo get the Virtual Network name attached to the VM use the ... Read More

How to retrieve the Azure subnets connected to the virtual network using PowerShell?

Chirag Nagrekar
Updated on 31-Aug-2021 09:38:11

2K+ Views

To get all the subnets attached to the virtual network using PowerShell, we need to use the GetAzVirtualNetwork command.PS C:\> $vn = Get-AzVirtualNetwork -Name VirtualNetworkNameTo get the Subnets and its address prefix details, you need to filter out the Subnets and AddressPrefixPS C:\> $vn.Subnets | Select Name, AddressPrefix

How out-gridview selection works in PowerShell?

Chirag Nagrekar
Updated on 01-Sep-2021 09:28:50

987 Views

With the PowerShell Out-Gridview output, you have an option to select one or multiple selections.For example, if we run the below command, it will show us the output in the grid format.PS C:\> Get-Process | Out-GridViewIn this output, you don’t get any option to select the rows because its output mode is none. To add the single selection from the output, use the Output mode to single, and for the multiple selections use the output mode to multiple. Once you add the OutpuMode property you can see the OK and Cancel button at the bottom right of the grid.Single output ... Read More

How to find the file modified after a certain date using PowerShell?

Chirag Nagrekar
Updated on 31-Aug-2021 08:48:36

14K+ Views

To get all the files that are modified after certain days, we need to use the LastWriteTime property.The below command shows us the files which are modified within the last 30 days in the C:\temp folder.Get-ChildItem C:\Temp | where{$_.LastWriteTime -ge (GetDate).AddDays(-30)}You can also use the AddMonths() or AddYears() instead of AddDays() as per your requirement.To get all the files that are modified before 30 days, use the below command.Get-ChildItem C:\Temp | where{$_.LastWriteTime -le (GetDate).AddDays(-30)}To get the file modified after a specific date, you need to compare the LastWriteTime with the Date. For example, we need all the files that are ... Read More

How to get the file extension using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 13:12:57

7K+ Views

We can retrieve the file extension using multiple ways. First, using the [System.IO.Path] class.PS C:\> [System.IO.Path]::GetExtension("C:\temp\25Aug2020.txt") .txt PS C:\> [System.IO.Path]::GetExtension("C:\temp\azcopy.zip") .zipThis is the easiest way to get the file extension. Otherways, Using programmatically, PS C:\> ((Split-Path "C:\Temp\azcopy.zip" -Leaf).Split('.'))[1] zip PS C:\> ((Split-Path "C:\Temp\25Aug2020.txt" -Leaf).Split('.'))[1] txtUsing Get-ChildItem, PS C:\> (Get-ChildItem C:\Temp\azcopy.zip).Extension .zip PS C:\> (Get-ChildItem C:\Temp\25Aug2020.txt).Extension .txtUsing Get-Item, PS C:\> (Get-Item C:\Temp\azcopy.zip).Extension .zipRead More

How to copy files of the specific extension using PowerShell?

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

986 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 the destination folder and then copy the content of the file but the problem with this command is it copies the subfolders as well which doesn’t have the .ps1 file.So to copy the with the same folder structure without empty directories and the specific file extension we can write the ... Read More

How to get the disabled local user accounts using PowerShell?

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 using the specific properties use the Select-Object pipeline command.PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true} | Select Name, FullName, CaptionYou can also use the CIM instance method alternatively, PS C:\> Get-CimInstance win32_useraccount | where{$_.Disabled -eq $true}To get the disabled accounts on the remote systems, use the -ComputerName parameter in ... Read More

Previous 1 ... 6 7 8 9 10 ... 47 Next
Advertisements