Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $WarningPreference = "SilentlyContinue"
- Set-ExecutionPolicy bypass -Scope CurrentUser -Force -Confirm:$false
- function prompt { 'PS [' + $(Get-Date) + '] ' + $(Get-Location) + '>' }
- Function tcping {
- param (
- [Parameter(Position=0)][string] $Server,
- [Parameter(Position=1)][string] $Port,
- [Parameter(Position=2)][int] $TimeOut = 2
- )
- if($Server -eq "") { $Server = Read-Host "Server" }
- if($Port -eq "") { $Port = Read-Host "Port" }
- if($Timeout -eq "") { $Timeout = 2 }
- [int]$TimeOutMS = $TimeOut*1000
- $IP = [System.Net.Dns]::GetHostAddresses($Server)
- $Address = [System.Net.IPAddress]::Parse($IP[0])
- $Socket = New-Object System.Net.Sockets.TCPClient
- Write-Host "Connecting to $Address on port $Port" -ForegroundColor Cyan
- Try {
- $Connect = $Socket.BeginConnect($Address,$Port,$null,$null)
- }
- Catch {
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Write-Host ""
- Return $false
- Exit
- }
- Start-Sleep -Seconds $TimeOut
- if ( $Connect.IsCompleted )
- {
- $Wait = $Connect.AsyncWaitHandle.WaitOne($TimeOutMS,$false)
- if(!$Wait)
- {
- $Socket.Close()
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Return $false
- }
- else
- {
- Try {
- $Socket.EndConnect($Connect)
- Write-Host "$Server IS responding on port $Port" -ForegroundColor Green
- Return $true
- }
- Catch { Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red }
- $Socket.Close()
- Return $false
- }
- }
- else
- {
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Return $false
- }
- Write-Host ""
- }
- function waitrdp($server) {
- while((tcping -server $server -port 3389) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
- function waithttp($server) {
- while((tcping -server $server -port 80) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
- function waitssl($server) {
- while((tcping -server $server -port 443) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
- function hosts {
- notepad c:\windows\system32\drivers\etc\hosts
- }
- function reboot {
- shutdown /r /t 0 /f
- }
- function poweroff {
- shutdown /s /t 0 /f
- }
- function hib {
- shutdown /h
- }
- function login {
- & \\corp.mydomain.com\netlogon\login.ps1
- }
- function eject($drive) {
- if(!$drive.Contains(':')) {$drive += ':'}
- if(!$drive.Contains('\')) {$drive += '\'}
- $vol = get-wmiobject -Class Win32_Volume | where{$_.Name -eq $drive}
- if($vol -ne $null) {
- $vol.DriveLetter = $null
- $vol.Put()
- $vol.Dismount($false, $false)
- }
- }
- function drag {
- Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name "DragFullWindows" -Value 1
- $setdrag=@"
- using System.Runtime.InteropServices;
- public class drag {
- [DllImport("user32.dll")]
- public static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags );
- public const int SPI_SETDRAGFULLWINDOWS = 0x0025;
- public static void setdrag() {
- int pv = 0;
- SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, ref pv, 3);
- }
- }
- "@
- Add-Type -TypeDefinition $setdrag
- [drag]::setdrag()
- }
- function clearcache() {
- Remove-Item $env:APPDATA\Microsoft\VisualStudio\14.0\ReflectedSchemas\*.* -Force -Confirm:$false -ErrorAction SilentlyContinue
- Remove-Item $env:TEMP\*.* -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue
- }
- function loginO365() {
- $azcred = get-credential
- Connect-MsolService -Credential $azcred
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://ps.outlook.com/PowerShell-LiveID?PSVersion=4.0' -Credential $azcred -Authentication Basic -AllowRedirection
- Import-PSSession $Session -AllowClobber
- }
- md C:\Scripts
- cd C:\Scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement