Steve Borba

My notes, I hope they help you, feel free to comment/add to them

Powershell Modules

I’m tired of having to find where to do this (and I have been rebuilding my PC so it is fresh in my head)

VMware:

install-module VMware.PowerCLI,PowerNSX

Azure:

install-module Azure,AzureRM

Search and install:

Find-Module | Out-GridView -OutputMode Multiple | Install-Module

Here is how to get powershell to complete like most cli’s (thank you Jeff):

Set-PSReadlineKeyHandler -Key Tab -Function Complete

Lets make is more permanent, add to your profile script (is there a better way to make this permanent?):

echo "Set-PSReadlineKeyHandler -Key Tab -Function Complete" >> $Profile

Garbage collect to reduce memory used:

[system.gc]::Collect()

If you want them to load when you open powershell, you could add to your profile script:

echo "Import-Module VMware.PowerCLI,PowerNSX" >> "$env:UserProfile\My Documents\WindowsPowerShell\profile.ps1"

Also, this makes my life easier(Thank you Jason!):

New-VICredentialStoreItem -Host Host -User Domain\user -Password ((get-credential).GetNetworkCredential().password)

ISE Font

$psISE.Options.FontName = 'Courier New' 

Export DHCP Scopes

$Leases = $null
$Scopes = $null

$DHCP_Servers = Get-DhcpServerInDC
foreach ( $DHCP_Server in $DHCP_Servers ) {
  $DHCP_Scopes = Get-DhcpServerv4Scope -ComputerName $DHCP_Server.DnsName -ErrorAction SilentlyContinue
  $Scopes += $DHCP_Scopes
  foreach ( $DHCP_Scope in $DHCP_Scopes ) {
    $Leases += $DHCP_Scope | Get-DhcpServerv4Lease -ComputerName $DHCP_Server.DnsName -ErrorAction SilentlyContinue
  }
}
$Leases | Export-Csv all-leases.csv
$Scopes | Export-Csv all-scopes.csv

Log and Display

filter Logging { ("$(Get-Date -Format u): $_") | Tee-Object -Append -FilePath ($ScriptRoot+$Prefix.Substring(0,$Prefix.Length - 1)+".log") }

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>