View measureSpeed
#-----------------------------------------------------
#1 - measure-command way
Measure-Command {Invoke-WebRequest `
-Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
-OutFile C:\rs-pkgs\test\profiles.ps1}
#-----------------------------------------------------
#2 - differencing datetime
$startMs = (Get-Date).Millisecond
Invoke-WebRequest `
-Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
View download_Web_File
#three ways to download a file using PowerShell
#example1: download a gist from github using webrequest
Invoke-WebRequest `
-Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
-OutFile C:\test\profiles.ps1
#example2: #download a gist from github using restmethod
Invoke-RestMethod `
-Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
View profiles
<#
.Synopsis
Evaluates all 6 PowerShell Profile locations and will indicate if they are present - and if so what they contain
.DESCRIPTION
Checks the location of all 6 PowerShell Profile to determine if there is a Profile file loaded there. If there is, the contents will be scanned so you can see what profile customizations are being loaded up.
.EXAMPLE
Test-PSProfiles
Checks all 6 PowerShell Profile locations and returns results
.EXAMPLE
View CustomPSObject
#working example of creating a multiple value custom PS Object
$TestObj = @()
$vms = get-vm
foreach($vm in $vms){
$name = $vm | Select-Object -ExpandProperty Name
$cpu = $vm | Select-Object -ExpandProperty ProcessorCount
$dyanamic = $vm | Select-Object -ExpandProperty DynamicMemoryEnabled
$memMin = [math]::round($vm.MemoryMinimum / 1MB, 0)
$memMax = [math]::round($vm.MemoryMaximum / 1GB, 0)
$TestObj += New-Object PSObject -Property @{
View hello_profile
# create profile if it does not yet exist
$exists = Test-Path -Path $Profile.CurrentUserAllHosts
if (!$exists){
New-Item -Path $Profile.CurrentUserAllHosts -ItemType File -Force | Out-Null
}
# add code to profile
$grettingsArray =
@'
$greetings =
'Hello there!',
View scrolling
dir c:\windows -Recurse -ea 0 | Out-Host -Paging
View preferred_node
function Move-VMsToPreferredNodes {
try {
#lets make sure the c:\rs-pkgs folder exists
#if it does not we will create it
$TARGETDIR = 'C:\rs-pkgs'
if (!(Test-Path -Path $TARGETDIR)) {
New-Item -ItemType directory -Path $TARGETDIR
}
#now we will identify all HA VMs
$haVMs = get-vm | ? { $_.IsClustered -eq $true }
View edit_hosts
$hostsPath = “$env:windir\System32\drivers\etc\hosts”
$hosts = get-content $hostsPath
$ip = "172.20.23.47"
$a=%{$ip}
$string = $a + “ MedSvr”
$hosts = $hosts + $string
$hosts | Out-File $hostsPath -enc ascii
View ps_variables
#get environment variables
ls env:\
#get console variables
Get-Variable
View SetDNS
$dns1 = "192.168.1.4"
$dns2 = "192.168.1.5"
#-----------------------------------------------------------
#i want to set the DNS for all adapters
try{
$adapters = Get-NetAdapter -ErrorAction Stop
foreach($adapter in $adapters){
Set-DnsClientServerAddress -InterfaceAlias $adapter.InterfaceAlias -ServerAddresses $dns1, $dns2 | Out-Null
}
}