Created
May 14, 2024 15:18
-
-
Save tsnaketech/845e6a06341fc64744a5d1b64a0a2da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Splunk-Start{ | |
| VBoxManage.exe startvm "Splunk" --type headless | |
| } | |
| function Splunk-Pause{ | |
| VBoxManage.exe controlvm "Splunk" pause --type headless | |
| } | |
| function Splunk-Resume{ | |
| VBoxManage.exe controlvm "Splunk" resume --type headless | |
| } | |
| function Splunk-Stop{ | |
| VBoxManage.exe controlvm "Splunk" poweroff --type headless | |
| } | |
| function Dsplunk-Start{ | |
| VBoxManage.exe startvm "Debian for Splunk" --type headless | |
| } | |
| function Dsplunk-Pause{ | |
| VBoxManage.exe controlvm "Debian for Splunk" pause --type headless | |
| } | |
| function Dsplunk-Resume{ | |
| VBoxManage.exe controlvm "Debian for Splunk" resume --type headless | |
| } | |
| function Dsplunk-Stop{ | |
| VBoxManage.exe controlvm "Debian for Splunk" poweroff --type headless | |
| } | |
| function CD-Python{ | |
| cd "D:\OneDrive\Script\Python" | |
| } | |
| function CD-Jupyter{ | |
| cd "D:\OneDrive\Script\Python\jupyter" | |
| } | |
| function CD-Venv{ | |
| cd "D:\OneDrive\Script\Python\venv" | |
| } | |
| function CD-Django{ | |
| cd "D:\OneDrive\Script\Python\venv\django" | |
| D:\OneDrive\Script\Python\venv\django\Scripts\Activate.ps1 | |
| } | |
| function Proxmox{ | |
| param ( | |
| [string[]]$vmid, | |
| [string[]]$action | |
| ) | |
| . D:\OneDrive\Script\Python\venv\venv\Scripts\Activate.ps1 | |
| python D:\OneDrive\Script\Python\finish\proxmox.py -v $vmid -a $action | |
| if ($env:VIRTUAL_ENV -ne $null) { | |
| deactivate | |
| } | |
| } | |
| function Reload-Profile { | |
| @( | |
| $Profile.AllUsersAllHosts, | |
| $Profile.AllUsersCurrentHost, | |
| $Profile.CurrentUserAllHosts, | |
| $Profile.CurrentUserCurrentHost | |
| ) | % { | |
| if(Test-Path $_){ | |
| Write-Verbose "Running $_" | |
| . $_ | |
| } | |
| } | |
| } | |
| function Test-Port | |
| { | |
| param ( | |
| [Parameter(Mandatory = $true, HelpMessage = "Indiquer le nom de l'ordinateur qui sera testé.")] | |
| $hostname, | |
| [Parameter(Mandatory = $true, HelpMessage = "Indiquer le port qui sera testé.")] | |
| $port | |
| ) | |
| # This works no matter in which form we get $host - hostname or ip address | |
| try { | |
| try | |
| { | |
| $hostname = [System.Net.Dns]::gethostentry($hostname).Hostname | |
| } | |
| Catch | |
| { | |
| Write-Warning "l'ordinateur $hostname n'a pas été résolu par le serveur DNS" | |
| } | |
| $Task = (New-Object System.Net.NetworkInformation.Ping).SendPingAsync($hostname) | |
| $ip = $Task.Result.Address.IPAddressToString | |
| } catch { | |
| Write-Warning "Il est possible que l'adresse $hostname est fausse" | |
| return | |
| } | |
| $t = New-Object Net.Sockets.TcpClient | |
| # We use Try\Catch to remove exception info from console if we can't connect | |
| try | |
| { | |
| $t.Connect($ip,$port) | |
| } catch {} | |
| if($t.Connected) | |
| { | |
| $t.Close() | |
| $msg = "Port $port sur l'adresse $ip est opérationnel" | |
| } | |
| else | |
| { | |
| $msg = "Port $port sur l'adresse $ip est bloqué, " | |
| $msg += "Il faudra contacter l'équipe réseau pour l'ouvrir." | |
| } | |
| $msg | |
| } | |
| function Test-SqlConnection { | |
| param( | |
| [Parameter(Mandatory)] | |
| [string]$ServerName, | |
| [Parameter(Mandatory)] | |
| [string]$DatabaseName, | |
| [Parameter(Mandatory)] | |
| [pscredential]$Credential | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| try { | |
| $userName = $Credential.UserName | |
| $password = $Credential.GetNetworkCredential().Password | |
| $connectionString = 'Data Source={0};database={1};User ID={2};Password={3}' -f $ServerName,$DatabaseName,$userName,$password | |
| $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $ConnectionString | |
| $sqlConnection.Open() | |
| ## This will run if the Open() method does not throw an exception | |
| $true | |
| } catch { | |
| $false | |
| } finally { | |
| ## Close the connection when we're done | |
| $sqlConnection.Close() | |
| } | |
| } | |
| # Import the Chocolatey Profile that contains the necessary code to enable | |
| # tab-completions to function for `choco`. | |
| # Be aware that if you are missing these lines from your profile, tab completion | |
| # for `choco` will not function. | |
| # See https://ch0.co/tab-completion for details. | |
| # $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
| # if (Test-Path($ChocolateyProfile)) { | |
| # Import-Module "$ChocolateyProfile" | |
| # } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment