Recommendations for powershell profile

As i showed in my post about creation of powershell profile you can add into profile your own frequently used functions.

I recommend to name them with permanent prefix. For example i create all my functions as moguy-cdp, moguy-esxi and so on.

In this case you don’t need to remember the name of your function to run, just start typing as moguy… and autocompletion will show you all your functions.

for example:

function moguy-vms

{

Get-VMHost | Get-VM | Select-Object Name, PowerState, NumCpu, MemoryMB, VMhost, @{N="Datastore";E={Get-Datastore -vm $_}}, UsedSpaceGB, ProvisionedSpaceGB, @{Name='ToolsVersion';Expression={$_.Guest.ToolsVersion}}, @{Name=’VMHostVersion’;Expression={$_.VMHost.Version}},Version, @{N="IP Address";E={@($_.guest.IPAddress[0])}},@{Name=’Cluster’;Expression={$_.VMHost.Parent}}, @{N="PortGroup";E={Get-VirtualPortGroup -VM $_}}, @{N="owner1";E={$_.customfields.item("owner1")}} | Export-Csv -path c:\temp\vms.csv -notypeinformation

}

function moguy-esxi

{

Get-VMHost |Select-Object Name,NetworkInfo,@{N="SerialNumber";E={(Get-VMHostHardware -vmhost $_).SerialNumber}}, @{ N="OutOfBandIP";E={(Get-VMHostWSManInstance -VMHost $_ -ignoreCertFailures -class OMC_IPMIIPProtocolEndpoint).IPv4Address}},Manufacturer,Model,ProcessorType, ConnectionState, PowerState, NumCpu,@{N="Cores/CPU";E={$_.Extensiondata.Summary.Hardware.NumCpuCores/$_.Extensiondata.Summary.Hardware.NumCpuPkgs}}, MemoryTotalGB, Version, Build, MaxEVCMode,@{N="Lockdown";E={$_.Extensiondata.Config.adminDisabled}},@{N="site";E={$_.customfields.item("00-site")}}, @{N="rack";E={$_.customfields.item("01-rack")}}, @{N="position";E={$_.customfields.item("02-rack-position")}},Parent | Export-Csv -notypeinformation -Path c:\temp\all-vmhosts.csv

}

function moguy-ntp-get1

{

Get-VMHost | Sort Name | Select Name, @{N="NTPServer";E={$_ |Get-VMHostNtpServer}}, Timezone, @{N="CurrentTime";E={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, @{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq "ntpd"}).Running}} ` | Format-Table -AutoSize

}

 

function moguy-ntp-get2

{

Get-VMHost | Get-VMHostService | Where-Object {$_.key -eq "ntpd"} | select vmhost, label, Key, Policy, Running, Required |format-table -autosize

}

 

function moguy-dc-time

{

"net time \\dc01","net time \\dc02","net time \\dc03","net time \\dc04" | ForEach-Object {cmd.exe /c $_}

}

 

function moguy-tag1

{

Get-VMHost | Get-VMHostHardware | Select-Object vmhost, SerialNumber | Export-Csv -NoTypeInformation -Path c:\temp\tag.csv

}

 

function moguy-tag2

{

Get-VMHost |get-view |Select-Object Name, @{Name="Serial Number"; Expression={($_.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq "ServiceTag"}).IdentifierValue}}

}

function moguy-ntp

{

Get-VMHost | Add-VMHostNtpServer -NtpServer 192.168.1.44

Get-VMHost | Get-VMHostService | Where-Object {$_.key -eq "ntpd" } | Start-VMHostService

Get-VMHost | Get-VMHostService | Where-Object {$_.key -eq "ntpd" } | Set-VMHostService -policy "automatic"

}

 

function moguy-round-robin

{

Get-VMHost | Get-ScsiLun -LunType disk | Where {$_.MultipathPolicy -notlike "RoundRobin"} | Set-Scsilun -MultiPathPolicy RoundRobin

}

function moguy-roundrobin-get

{

Get-Vmhost | Get-Scsilun | Select-Object CanonicalName, ConsoleDeviceName,LunType, CapacityGB, MultipathPolicy, vmhost | export-csv -NoTypeInformation -path c:\temp\roundrobin.csv

}




In the same way you can add into autorun all your powershell modules (and surely beforehand you should install all these modules, the downside is the slow start of powershell ISE)
Or you can auto connect to your vmware vcenter or Veeam Backup and Replication server.
import-module activedirectory
Import-Module SkypeforBusiness
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
import-module HPEiLOCmdlets
import-module HPENimblePowerShellToolkit
Add-PSSnapin VeeamPSSnapin

connect-viserver vcsa.itforce.local
Connect-VBRServer -server 192.168.1.100