Advertisement
timsstuff

$profile

Aug 8th, 2017
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $WarningPreference = "SilentlyContinue"
  2.  
  3. Set-ExecutionPolicy bypass -Scope CurrentUser -Force -Confirm:$false
  4.  
  5. function prompt { 'PS [' + $(Get-Date) + '] ' + $(Get-Location) + '>' }
  6.  
  7. Function tcping {
  8.        param (
  9.               [Parameter(Position=0)][string] $Server,
  10.               [Parameter(Position=1)][string] $Port,
  11.               [Parameter(Position=2)][int] $TimeOut = 2
  12.        )
  13.        
  14.        if($Server -eq "") { $Server = Read-Host "Server" }
  15.        if($Port -eq "") { $Port = Read-Host "Port" }
  16.        if($Timeout -eq "") { $Timeout = 2 }
  17.        [int]$TimeOutMS = $TimeOut*1000
  18.        $IP = [System.Net.Dns]::GetHostAddresses($Server)
  19.        $Address = [System.Net.IPAddress]::Parse($IP[0])
  20.        $Socket = New-Object System.Net.Sockets.TCPClient
  21.        
  22.        Write-Host "Connecting to $Address on port $Port" -ForegroundColor Cyan
  23.        Try {
  24.               $Connect = $Socket.BeginConnect($Address,$Port,$null,$null)
  25.        }
  26.        Catch {
  27.               Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
  28.               Write-Host ""
  29.         Return $false
  30.               Exit
  31.        }
  32.        
  33.        Start-Sleep -Seconds $TimeOut
  34.        
  35.        if ( $Connect.IsCompleted )
  36.        {
  37.               $Wait = $Connect.AsyncWaitHandle.WaitOne($TimeOutMS,$false)                
  38.               if(!$Wait)
  39.               {
  40.                      $Socket.Close()
  41.                      Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
  42.             Return $false
  43.               }
  44.               else
  45.               {
  46.                      Try {
  47.                            $Socket.EndConnect($Connect)
  48.                            Write-Host "$Server IS responding on port $Port" -ForegroundColor Green
  49.                 Return $true
  50.                      }
  51.                      Catch { Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red }
  52.                      $Socket.Close()
  53.             Return $false
  54.               }
  55.        }
  56.        else
  57.        {
  58.               Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
  59.         Return $false
  60.        }
  61.        Write-Host ""
  62.  
  63. }
  64.  
  65. function waitrdp($server) {
  66.     while((tcping -server $server -port 3389) -eq $false) {start-sleep -s 5}
  67.     if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
  68.         $sound = new-Object System.Media.SoundPlayer
  69.         $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
  70.         $sound.Play()
  71.     }
  72. }
  73.  
  74. function waithttp($server) {
  75.     while((tcping -server $server -port 80) -eq $false) {start-sleep -s 5}
  76.     if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
  77.         $sound = new-Object System.Media.SoundPlayer
  78.         $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
  79.         $sound.Play()
  80.     }
  81. }
  82.  
  83. function waitssl($server) {
  84.     while((tcping -server $server -port 443) -eq $false) {start-sleep -s 5}
  85.     if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
  86.         $sound = new-Object System.Media.SoundPlayer
  87.         $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
  88.         $sound.Play()
  89.     }
  90. }
  91.  
  92. function hosts {
  93.     notepad c:\windows\system32\drivers\etc\hosts
  94. }
  95.  
  96. function reboot {
  97.     shutdown /r /t 0 /f
  98. }
  99.  
  100. function poweroff {
  101.     shutdown /s /t 0 /f
  102. }
  103.  
  104. function hib {
  105.     shutdown /h
  106. }
  107.  
  108. function login {
  109.     & \\corp.mydomain.com\netlogon\login.ps1
  110. }
  111.  
  112. function eject($drive) {
  113.     if(!$drive.Contains(':')) {$drive += ':'}
  114.     if(!$drive.Contains('\')) {$drive += '\'}
  115.     $vol = get-wmiobject -Class Win32_Volume | where{$_.Name -eq $drive}  
  116.     if($vol -ne $null) {
  117.         $vol.DriveLetter = $null  
  118.         $vol.Put()  
  119.         $vol.Dismount($false, $false)
  120.     }
  121. }
  122.  
  123. function drag {
  124.     Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name "DragFullWindows" -Value 1
  125.     $setdrag=@"
  126. using System.Runtime.InteropServices;
  127. public class drag {
  128.    [DllImport("user32.dll")]
  129.    public static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags );
  130.    
  131.    public const int SPI_SETDRAGFULLWINDOWS = 0x0025;
  132.    
  133.    public static void setdrag() {
  134.        int pv = 0;
  135.        SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, ref pv, 3);
  136.    }
  137. }
  138. "@
  139. Add-Type -TypeDefinition $setdrag
  140. [drag]::setdrag()
  141. }
  142.  
  143. function clearcache() {
  144.     Remove-Item $env:APPDATA\Microsoft\VisualStudio\14.0\ReflectedSchemas\*.* -Force -Confirm:$false -ErrorAction SilentlyContinue
  145.     Remove-Item $env:TEMP\*.* -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue
  146. }
  147.  
  148. function loginO365() {
  149.     $azcred = get-credential
  150.     Connect-MsolService -Credential $azcred
  151.     $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://ps.outlook.com/PowerShell-LiveID?PSVersion=4.0' -Credential $azcred -Authentication Basic -AllowRedirection
  152.     Import-PSSession $Session -AllowClobber
  153. }
  154.  
  155. md C:\Scripts
  156. cd C:\Scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement