The default Linux prompt gives you additional helpful information while working through a session instead of Windows.
The example below displays a user who is logged in along with the hostname in a windows command line.
1 2 3 |
C:\Windows\system32>set prompt=[%username%@%computername% $P]# [strachotao@PC101 C:\Windows\system32]# |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<# .Synopsis Check file header if it is a JPG file .EXAMPLE Check one file: Test-JPGHeader -File c:\temp\myPicture.jpg .EXAMPLE Check all jpeg files in one folder (ls c:\pictures\*.jpg ).FullName | % {if ((Test-JPGHeader -File $_) -eq $false) {Write-Host "$_ is not real JPG"}} .NOTES If file doesn't exists, function returns false #> Function Test-JPGHeader { Param ([Parameter(Mandatory=$true, Position=0)] [String]$File) $Result = $false if ((Test-Path $File) -eq $false) { Return $Result Break; } [String]$JPG = "255216255" [Byte[]]$RAWHeader = Get-Content $File -TotalCount 3 -Encoding Byte [String]$Header += $RAWHeader $Header = $Header.Replace(" ","") $Result = $JPG -contains $Header Return $Result } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<# .Synopsis Function to validate a IP address .EXAMPLE Test-IPAddress "10.0.0.1" Test-IPAddress "fe80::38f3:ecce:1907:a128%18" .OUTPUT True or False #> Function Test-IPAddress { Param ([Parameter(Mandatory=$true, ValueFromPipeline=$true)] [string]$IP) [System.Net.IPAddress]::TryParse($IP,[ref]$null) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<# .Synopsis Function to get a IP address using NSlookup .EXAMPLE Get-IPviaNSlookup -hostname pc001 Get-IPviaNSlookup -hostname pc001 -server dns3 .OUTPUTS Output from this function is a IP or IPs returned from the DNS server via nslookup #> Function Get-IPviaNSlookup { Param ([Parameter(Mandatory=$true, ValueFromPipeline=$true)] [string]$hostName, [Parameter(Mandatory=$false, ValueFromPipeline=$true)] [string]$server = "") $nslookupCommand = nslookup "$hostname" 2> null if ($server -ne "") { if (Test-Connection $server -Quiet -Count 1){ $nslookupCommand = nslookup "$hostname" "$server" 2> null } else { Write-Host "Can't find server $server" -ForegroundColor Red Exit } } [string]$rawData = $nslookupCommand $regex = "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" $counter = 0 $rawData | Select-String -Pattern $regex -AllMatches | foreach {$_.Matches} | foreach { if ($counter -gt 0) { $_.Value } $counter++ } } |