Skip to content

Instantly share code, notes, and snippets.

View itpropro's full-sized avatar
🏠
Working from home

Jan-Henrik Damaschke itpropro

🏠
Working from home
View GitHub Profile
#Does not work with DSC Configurations, using the $using: variable to change scopes
Invoke-Command -ScriptBlock (Get-Command .\DSCConfig.ps1|select -ExpandProperty ScriptBlock) -ComputerName localhost
Invoke-Command -FilePath ('.\' + $DSCConfig + '.ps1') -ComputerName localhost
#Does work with $using because of the -NoNewScope switch
Invoke-Command -ScriptBlock (Get-Command .\DSCConfig.ps1|select -ExpandProperty ScriptBlock) -NoNewScope
#Applies the pending configuration
Invoke-CimMethod -Namespace root\Microsoft\Windows\DesiredStateConfiguration -ClassName MSFT_DSCLocalConfigurationManager -MethodName ApplyConfiguration
#Starts a consistency check for the last applied config
Invoke-CimMethod -Namespace root\Microsoft\Windows\DesiredStateConfiguration -ClassName MSFT_DSCLocalConfigurationManager -MethodName PerformRequiredConfigurationChecks -Arguments @{Flags = [uint32]1}
$nics = Get-CimInstance Win32_NetworkAdapter -Filter 'netenabled = true'
$powerenabled = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceWakeEnable
$nics|% {if ($powerenabled.InstanceName -match [regex]::Escape($_.PNPDeviceID)) {$powernics = $_.PNPDeviceID}}
$Items = $powerenabled|Where-Object {$_.InstanceName -like "$powernics*"}
$Items.Enable = $true
Set-CimInstance -InputObject $Items
$ips = @()
foreach ($i in 1..254)
{
$ips += "192.168.0.$i"
}
New-NetFirewallRule -Protocol TCP –LocalPort 3389 -Profile Public -DisplayName 'RDP VPN S2S' -Direction Inbound -Action Allow -RemoteAddress $ips
$OFS =’; ’
$Job = {Get-VM|Stop-VM}
Start-Job $Job
While((Get-VM|? State -NE 'Off').Count -gt 0) {Write-Host 'VMs' ([string](Get-VM|? State -ne 'Off').Name) 'shutting down...';Start-Sleep 1}
Stop-Computer -Force
$message = "The size of your desktop folder exceeds 500MB.`r`nThis can cause delays at logon and logoff.`r`n`r`nGreetings from your IT-Department"
if ([Math]::Truncate((Get-ChildItem "$env:USERPROFILE\Desktop" -Recurse|Measure-Object -property Length -sum).Sum / 1MB) -gt 500){[System.Windows.Forms.MessageBox]::Show($message)}
cmdkey /generic:{HYPER-V SERVER}\{VMNAME} /user:{USERNAME} /pass:{PASSWORD}
C:\WINDOWS\system32\VmConnect.exe "{HYPER-V SERVERNAME}" "{VMNAME}" [/credential LegacyGeneric:target={CREDENTIALNAME} | /user {USERNAME} /password {PASSWORD}]
# MD5 for String
$hash = [System.Security.Cryptography.MD5]::Create()
$byte = [System.Text.Encoding]::UTF8.GetBytes('Test')
$md5 = $hash.ComputeHash($byte)
([Bitconverter]::ToString($md5)).replace('-','')
# MD5 for File
$hash = [System.Security.Cryptography.MD5]::Create()
$file = [System.IO.File]::ReadAllBytes('E:\Onedrive\Dokumente\Skripte\Powershell Skripte\test.zip')
$md5 = $hash.ComputeHash($file)
$name = 'Dammaschke' # Change
$NetworkCategory = 1 # 0 = Public, 1 = Private (2 = Domain, but not setable)
$profile = Get-CimInstance -Namespace root/StandardCimv2 -ClassName MSFT_NetConnectionProfile|Where-Object Name -EQ $name
$profile.NetworkCategory = $NetworkCategory
Set-CimInstance $profile
function Get-SidfromHex {
param
(
[string]$Sid
)
$ByteSid = New-Object Byte[] 150
for ($i = 0; $i -lt $Sid.Length ; $i += 2) {
$ByteSid.Set(($i/2),([Byte]::Parse($Sid.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber)))
}