This file contains 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
#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 |
This file contains 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
#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} |
This file contains 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
$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 |
This file contains 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
$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 |
This file contains 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
$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 |
This file contains 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
$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)} |
This file contains 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 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))) | |
} |
This file contains 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 Get-NtSecurityDescriptor { | |
param | |
( | |
[string]$SecurityDescriptor | |
) | |
$ntsecdesc = New-Object Byte[] ($SecurityDescriptor.Length) | |
for ($i = 0; $i -lt $SecurityDescriptor.Length ; $i += 2) { | |
$ntsecdesc.Set(($i/2),([Byte]::Parse($SecurityDescriptor.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber))) | |
} |
This file contains 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
[DscLocalConfigurationManager()] | |
Configuration PullClientV2 { | |
param( | |
[Parameter(Mandatory=$True)] | |
[String]$ConfigurationNames, | |
[Parameter(Mandatory=$True)] | |
[String]$Server | |
) | |
Settings | |
{ |
This file contains 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
# When a document is created in D:\Test with the extension .rtf This script will print its name | |
Register-CimIndicationEvent -Query "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE | |
TargetInstance ISA 'CIM_DataFile' AND (TargetInstance.Drive='D:' AND TargetInstance.Path='\\Test\\' AND TargetInstance.Extension='rtf')" -Action { | |
Write-Host $($Event.SourceEventArgs.NewEvent.TargetInstance.Name) | |
} |
OlderNewer