Skip to content

Instantly share code, notes, and snippets.

CosmosKey

Block or report user

Report or block CosmosKey

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@CosmosKey
CosmosKey / AbortShutdown.ps1
Created Apr 22, 2019
Abort Windows Shutdown
View AbortShutdown.ps1
$definition = @'
using System;
using System.Runtime.InteropServices;
public class W32ShutdownUtil {
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool AbortSystemShutdown(String machineName);
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
View IsePrank.ps1
While ( $True ) { $PSise.Options.Zoom = 100 + 10 * [math]::sin( (Get-Date).TimeOfDay.TotalSeconds ); Sleep -Milliseconds 40 }
@CosmosKey
CosmosKey / Get-ADGroupMemberSamAccountName
Created Feb 27, 2018
Get-ADGroupMemberSamAccountName
View Get-ADGroupMemberSamAccountName
Function Get-ADGroupMemberSamAccountName {
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]$GroupName
)
process {
$name = $GroupName
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$dc = $domain.FindDomainController([System.DirectoryServices.ActiveDirectory.LocatorOptions]::WriteableRequired)
View Attribtue Scope Query sample.ps1
$Name = "MSFT-Office 365 Enterprise E1"
$groupSearcher = [adsisearcher]"(samaccountname=$Name)"
$group = $groupSearcher.FindOne()
$memberSearch = [adsisearcher]::new($group.GetDirectoryEntry(),"(&(objectClass=user)(objectCategory=Person))",[string[]]'samaccountname','base')
$memberSearch.AttributeScopeQuery = "member";
foreach($member in $memberSearch.FindAll())
{
$member.Properties['samaccountname']
}
@CosmosKey
CosmosKey / SelectBuildingAndOfficeForm.ps1
Last active Dec 28, 2017
SelectBuildingAndOfficeForm.ps1 A piece of DropDown Forms sample code
View SelectBuildingAndOfficeForm.ps1
# DropDown Data
$office = @{
'HQ' = 'Ground floor','1st floor','2nd floor','3rd floor'
'Garage' = 'Shop floor','Office'
'Sales office' = 'Ground floor','1st floor'
}
# Load assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
@CosmosKey
CosmosKey / Get-CertificateChain.ps1
Created Sep 9, 2017
Get-CertificateChain.ps1
View Get-CertificateChain.ps1
Function Get-CertificateChain {
param(
[string]$server=$(throw "Mandatory parameter -Server is missing."),
[int]$port=$(throw "Mandatory parameter -Port is missing."),
[switch]$ToBase64
)
$code=@"
using System;
using System.Collections;
using System.Net;
@CosmosKey
CosmosKey / ConsoleCursorLab.ps1
Created Aug 26, 2017
Console Cursor Lab, handling cursors in [console]
View ConsoleCursorLab.ps1
Write-Host "Done Name State HasData"
$global:js = [System.Collections.ArrayList]::new()
for($i=0;$i -lt 10;$i++){
$j = Start-Job {"JOB" + $using:i;Start-Sleep -Milliseconds (Get-Random -Maximum 3000 -Minimum 0) } -Name "MyJob-$i"
$j | Add-Member -Name CursorTop -MemberType NoteProperty -Value ([console]::CursorTop) -Force
[void]$js.Add($j)
Write-Host "x " -ForegroundColor Red -NoNewline
Write-Host ("{0} {1} {2}" -f $j.Name,$j.State,$j.HasMoreData)
}
[console]::CursorVisible = $false
View Build a quick sample module with a manifest.
$ModuleName = "MyTestModule"
$userModulePath = $env:PSModulePath.Split(";") -like "*\$env:USERNAME\*"
New-Item -Path "$userModulePath\$ModuleName" -ItemType Directory -Force | Out-Null
{function Get-Zero{0}function Get-One{1}}|Set-Content "$userModulePath\$ModuleName\$ModuleName.psm1"
New-ModuleManifest -Path "$userModulePath\$ModuleName\$ModuleName.psd1" -RootModule "$ModuleName.psm1" -FunctionsToExport "Get-Zero"
Get-Module -ListAvailable -Name $ModuleName
Get-Zero
@CosmosKey
CosmosKey / Launch program remotely through CIM over DCOM.ps1
Created Feb 21, 2017
Launch program remotely through CIM over DCOM
View Launch program remotely through CIM over DCOM.ps1
$cimSessionOption = New-CimSessionOption -Protocol Dcom
$cimSession = New-CimSession -ComputerName $env:computername -SessionOption $cimSessionOption
Invoke-CimMethod -CimSession $cimSession -ClassName win32_process -methodname Create -Arguments @{
commandline = "powershell.exe -executionpolicy bypass -file \\$env:computername\c`$\ps\test.ps1"
}
@CosmosKey
CosmosKey / PowerShellGet - Setup Local Repo.ps1
Created Feb 16, 2017
PowerShellGet - Setup a local repository demo
View PowerShellGet - Setup Local Repo.ps1
###############################################################
#
# A quick look at setting up local PowerShellGet repositories
#
###############################################################
#
# Find and install a module from PSGallery
You can’t perform that action at this time.