Basic Powershell commands

On this page some simple but useful Powershell commands are shown. These commands are the basics of the usage of Powershell.

To search all Powershell cmdlets for a keyword the ‘Get-Command’ command can be used. The ‘Get-Command’ can be abbreviated to ‘gcm’. To search for all commands that contain the word ‘network’ you can use the following commands.

gcm

Get-Command

It is also possible to serach within a specific module. To search in the NetTCPIP module the following command can be used:

Module

If you need to know more about a specific cmdlets you can use the ‘Get-Help’ command followed by the command you want to have more information about.

Get-Help

If you want to know the details of an cmdlet the ‘Get-Member’ command can be used. If you for example want to know what information can be shown with the ‘Get-Process’ command the following command can be used:

Get-Member

Within an output you can search for a specific value. To search for specific values you can use the ‘Where-Oject’ command. In this example we search for all processes named MMC.

Where-Object

The first thing the code is doing is getting a list of processes on our computer and passing the output (using the | character) to our Where-Object cmdlet. The cmdlet takes a script block as a parameter. The script block instructs the Where-Object cmdlets to only select objects where their name parameter is equal to ‘mmc’. The result is a list of the MMC instances that are running.

To stop all the instances of MMC that are running you can pipe the output to a ‘Stop-Process’ command.

Stop-Process

Delen via: Facebooktwitterpinterestlinkedinmail

VMware PowerCLI script to add storage and VLAN’s

When deploying multiple VMware hosts you can use the Template feature in vSphere. If you’re not licenced to use the template feature in vSphere you can use the VMware PowerCLI PowerShell commands to quickly add the strorage and the networks.

First thing you got to do is connect to the host:

  • Connect-VIServer -Server esx.jvr.local

To add VLAN’s to a vSwitch use the following command:

  • get-vmhost -name esx.jvr.local | Get-VirtualSwitch -name vSwitch0 | new-VirtualPortGroup -name “LAN” -vlanid 0
  • get-vmhost -name esx.jvr.local | Get-VirtualSwitch -name vSwitch0 | new-VirtualPortGroup -name “PVS” -vlanid 2310

To add NFS storage use the following commands:

  • get-vmhost -name esx.jvr.local | New-Datastore -Nfs -Name ESX1 -Path /NAS_ESX1 -NfsHost 10.10.10.50

This can also be done at the cluster level. The following command’s can be used:

  • Get-Cluster “CLUSTER_1” | Get-VMHost | Get-VirtualSwitch -name vSwitch1 | New-VirtualPortGroup -name “PVS” -VLanId 2310
  • Get-Cluster “CLUSTER_1” | Get-VMHost | Get-VirtualSwitch -name vSwitch1 | New-VirtualPortGroup -name “HB” -VLanId 2309
Delen via: Facebooktwitterpinterestlinkedinmail

Basic App-V 5 Client PowerShell Commands

These PowerShell commands should be run on an App-V 5 Client computer. The first step is importing the App-V module, as it’s not imported by default.

  • Import-Module AppvClient

This must be run to import the module to allow PowerShell to run PowerShell cmdlets for the App-V 5 Client.

  • Get-Command -Module Appvclient

This gets a list of PowerShell commands for the App-V Client module.

  • Add-AppvPublishingServer -Name [Name of App-V Publishing Server] -URL [URL]

Adds the specified App-V 5 Publishing Server to the App-V 5 Client.

  • Sync-AppvPublishingServer -Name [Name of App-V Publishing Server]

Syncs the App-V 5 Client’s apps with the App-V 5 Publishing Server.

  • Add-AppvClientPackage \\Servername\Sharename\Appfilename.appv

Adds a package to the local App-V 5 Client.

  • Add-AppvClientPackage \\Servername\Sharename\Appfilename.appv | Publish-AppvClientPackage -Global
Delen via: Facebooktwitterpinterestlinkedinmail

Invoke PowerShell commands to multiple servers at the same time

One of the best things of PowerShell is that you can invoke commands to multiple servers at once. This can save a lot of time when implementing new features or troubleshooting errors. The PowerShell Command that makes this possible is:

  • Invoke-Command -ComputerName [Computername1], [Computername1] -command {[PowerShell Command here]}

In this example i have installed the Windows Clustering Feature on three different servers with the following command:

  • Invoke-Command -ComputerName 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools}

2014-10-25 15_11_29-mRemoteNG - confCons.xml

In this example i have added a Firewall rule on three different servers with the following command:

  • Invoke-Command -Computername 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {New-NetFirewallRule -DisplayName “SQL Server Browser Service” -Direction inbound –LocalPort 1434 -Protocol TCP -Action Allow -Profile Domain}

In this example i have specified the sxs folder:

  • Install-WindowsFeature –name NET-Framework-Core -source \\[Servername]\sxs -ComputerName 2012R2-AS07
Delen via: Facebooktwitterpinterestlinkedinmail