if (Test-Path $path) { Write-Host "File exists." } if (!(Test-Path $path)) { Write-Host "File does not exist." }
if ($?) { Write-Host 'Success' -ForegroundColor Green } else { Write-Host 'FAILED' -ForegroundColor Red throw 'Failed.' }
Get-ChildItem -Recurse -Path C:\Temp -Include *.txt | Select-String 'This', 'OR that' | Select-String 'AND this' | Format-Table -property path, line -autosize | Out-String -Width 4096
(Get-Content $filename) -replace 'heise', 'Heise' | Set-Content $filename
$timestamp = (Get-Date).ToString("yyyyMMdd HHmmssff")
param ( [parameter(Mandatory=$true,HelpMessage='The target server')] [string]$targetServer, [parameter(Mandatory=$true)] [string]$targetWebConfig, [parameter(Mandatory=$false)] [string]$build = 'debug' )
Push-Location "$($MyInvocation.MyCommand.Path)\..\" #... Pop-Location
Search by thumbprint:
Get-ChildItem -Path Cert: -Recurse | Where-Object { $_.Thumbprint -and $_.Thumbprint.ToLower().StartsWith('c4') }
To check if the cert is valid, pipe it the Test-Certificate
command:
Get-ChildItem -Path Cert: -Recurse | Where-Object { $_.Thumbprint -and $_.Thumbprint.ToLower().StartsWith('c4') } | Test-Certificate
To check for expired / revoked certs:
$certs = Get-ChildItem -Path Cert:\LocalMachine\My -Recurse foreach ($cert in $certs) { Write-Host "$($cert.Thumbprint) $($cert.Subject)" if ($certs.NotAfter -lt (Get-Date)) { Write-Host " Expired on $($certs.NotAfter)" -ForegroundColor Red } elseif ($cert | Test-Certificate) { Write-Host " Tested ok." -ForegroundColor Green } }
notepad $PROFILE
.# Uncomment this to use PowerShellGet #$Username="global\heises" #$Password="password" #[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://10.104.66.70:80') #[system.net.webrequest]::defaultwebproxy.credentials = New-Object System.Net.NetworkCredential($Username, $Password) #[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
Register-PSRepository -Default
Get-PSRepository
again to verify.If this doesn't work, and it won't for an ANZ Dev VM, try the PowerShell Manual Module Installation.
May only work inside Windows Powershell ISE.
$intervalSeconds = 60 $mouseDistance = 1 $myshell = New-Object -com "Wscript.Shell" while ($true) { Start-Sleep -Seconds $intervalSeconds $Pos = [System.Windows.Forms.Cursor]::Position [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) + $mouseDistance) , $Pos.Y) [System.Windows.Forms.SendKeys]::SendWait("{f15}") Write-Host 'A shuffle to the right.' Start-Sleep -Seconds $intervalSeconds $Pos = [System.Windows.Forms.Cursor]::Position [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) - $mouseDistance) , $Pos.Y) [System.Windows.Forms.SendKeys]::SendWait("{f15}") Write-Host 'A shuffle to the left.' }
'1234abcd' -replace '\d', '*' # ****abcd
'123.456.789.123' -match '\d+(?:\.\d+){2}' # returns true if there is a match. $Matches.Values # = '123.456.789'
$inputText = '!! Match me Not me !! Match me too Not me tho' $regex=[regex] '(?m)^!!.+?$' $regex.matches($inputText) | Foreach-Object { $_.Value } # Returns a string, one match per line.
# Filter lines by regex. $inputText = ' .. . . left:10 . .. right:10 ... .. . . left:20 . .. right:20 ... .. . left:30 . . ... .. right:30 ... left:40right:40' -replace "`r`n", "`n" $regex=[regex] '(?m)^[ \.]*(?<left>left:\d+)[ \.]*(?<right>right:\d+)[ \.]*$' $regex.matches($inputText) | Foreach-Object { $_.Groups["left"].value + ' - ' + $_.Groups["right"].value} # Returns a string: #left:10 - right:10 #left:20 - right:20 #left:30 - right:30 #left:40 - right:40
$regex=[regex] ('-rw-rw---- 1 root sdcard_rw (?<length>\d+) (?<date>\d\d\d\d-\d\d-\d\d \d\d:\d\d) (?<filename>.*)$') $input='-rw-rw---- 1 root sdcard_rw 358 2019-09-01 19:50 /storage/emulated/0/Podcasts/Sync Test/New folder/rua.txt' $matches = $regex.matches($input) if (!($matches.Success)) { Write-Host "Regex failed to match: $input" -ForegroundColor Red Exit(-1) } Write-Host "length = $($matches.Captures.Groups["length"].value)" Write-Host "date = $($matches.Captures.Groups["date"].value)" Write-Host "filename = $($matches.Captures.Groups["filename"].value)"
# $1 = group 1, $2 = group 2, etc. '123 456 789' -replace '(\d+ )(\d+)( \d+)', '$1!$2!$3' # = '123 !456! 789'