powershell

Powershell Help

Help Get-Help Get-Service Aliases man or help uses the more command Update Help Powershell 3 and higher Update-Help Display the full help with -full Help Get-EventLog -full Display help in a separate window with -ShowWindow Get-Help Get-Help -ShowWindow Get-Help Get-Help Get-Process Get-Help Get-Process -Online Find a command Get a list of command Get-Help *eventlog* Get-Command *eventlog* About topics Powershell has a lot of about topics help about* help about_break help about_operators Show-Command Display a form »

Powershell Providers Psdrive Manage Files and Folders

Set working directory Set-Location -Path C:\Windows\ PS providers get loaded providers Get-PSProvider Get available PSDrives Get-PSDrive Alias Alias C 85,15 137,93 FileSystem C:\ Cert Certificate \ D 0,33 0,15 FileSystem D:\ E 251,40 680,11 FileSystem E:\ Env Environment Function Function G 44,33 29,71 FileSystem G:\ H FileSystem H:\ HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE Variable Variable WSMan WSMan Create new PS drive New-PSDrive Install FileSystem \\biz-dc1\Install Registry cd hklm: cd . »

Selecting and Sorting Objects

Select properties to show Let you select object (the selected objects will be the only objects you can use). Get-Process | Select-Object -Property Name,ID,VM,PM Get-Process | Select Name,ID,VM,PM Get-ChildItem | Select-Object -Property Name,Directory Get-ChildItem | Select -Property Name,Directory Sorting Get-Process | Sort-Object -property VM -descending Get-Process | Sort VM -desc Select last or first items Get-Process | Select-Object -First 10 Get-Process | Select-Object -Last 10 Select ExpandProperty need more information on this »

Formatting

Format-Table Resize the table with Get-Process | ft -AutoSize Get-Process | Format-Table Select properties Get-Process | Format-Table -property * Get-Process | Format-Table -property ID,Name,Responding -autoSize Get-Process | Format-Table * -autoSize Group By Get-Service | Sort-Object Status | Format-Table -groupBy Status Rename Column Get-Service | Format-Table @{n='ServiceName';e={$_.Name}},Status,DisplayName Select columns and calculate size Get-Process | Format-Table Name, @{n='VM(MB)';e={$_.VM / 1MB -as [int]}} -autosize Format-List Get-Process | Format-List Format-Wide Get-Process | format-wide Get-Process | fw -AutoSize Get-Process | fw -Column 3 Out-GridView Create a pop-up with a grid, sorting grid an search box »

Azure VM Powershell create

Quickly create a new VM New-AzVm ` -ResourceGroupName "myResourceGroup" ` -Name "myVM" ` -Location "East US" ` -VirtualNetworkName "myVnet" ` -SubnetName "mySubnet" ` -SecurityGroupName "myNetworkSecurityGroup" ` -PublicIpAddressName "myPublicIpAddress" ` -OpenPorts 80,3389 Specify $cred = Get-Credential # Create the initial configuration $vm = New-AzVMConfig -VMName myVM -VMSize Standard_Ds1_v2 # Set the operating system $vm = Set-AzVMOperatingSystem ` -VM $vm ` -Windows ` -ComputerName myVM ` -Credential $cred ` -ProvisionVMAgent -EnableAutoUpdate # Set the image information $vm = Set-AzVMSourceImage ` -VM $vm ` -PublisherName MicrosoftWindowsServer ` -Offer WindowsServer ` -Skus 2016-Datacenter ` -Version latest # Create the VM New-AzVM -ResourceGroupName myResourceGroupVM -Location EastUS -VM $vm »

Azure VM Powershell

Management commands Get status of a machine Get-AzVM get-azvm -status get-azvm -name SimpleWinVM -ResourceGroupName deploymentgroup Update VM settings $ResourceGroupName = "deploymentgroup" $vm = Get-AzVM -Name SimpleWinVM -ResourceGroupName $ResourceGroupName $vm.HardwareProfile.vmSize = "Standard_A3" Update-AzVM -ResourceGroupName $ResourceGroupName -VM $vm Creating machines See Azure Virtual Machine create with Powershell. # New VM simple New-AzVM -name azvm1 -ResourceGroupName azgroup1 Azure Virtual Machine Sample Scripts »

Powershell Remote

Enable Powershell remote on Windows Core On the remote endpoint enable Enable-PSRemoting -Force Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP" -RemoteAddress Any Mak sure the firewall profile is set to private or domain. PS remote outside domain If the local machine is not inside the same domain you need to add the romote endpoint as a trusted host. MITM still posible. On local machine add the remote endpoint in wsman # Add one item Set-Item WSMan:\localhost\Client\TrustedHosts -Value "FQDN-or-IP" # Add a next one if needed (see Get-Item) Set-Item WSMan:\localhost\Client\TrustedHosts -Value "FQDN-or-IP" -Concatenate #Then restart WinRM Restart-Service WinRM Test the connection »