Skip to content

Instantly share code, notes, and snippets.

@belotn
belotn / l4account.ps1
Created June 27, 2013 14:22
Look for published apps for an "Account"
get-xaapplication |% { get-xaapplicationreport -BrowserName $_.BrowserName |? { $_.Accounts -contains MyAccount} | select BrowserName }
@belotn
belotn / onescan_fillsqllite.ps1
Created July 9, 2013 14:41
Load an SQLite DB with filtered and modified content from eventlog
get-eventlog -LogName "Key Management Service" -ComputerName "COMPNAME" -InstanceId 1073754114 | select Index,Message |% {if ($_.MEssage -match ".*(0x[0-9a-f]+),(\d+),([^,]+),([0-9a-f\-]+),([^,]+),(\d),(\d),(\d+),([0-9a-f\-]+).*") { $_ | Add-Member -type NoteProperty -name Client -Value $matches[3] -Passthru | Add-Member -type NoteProperty -name CMID -Value $matches[4] -PassThru | Add-Member -type NoteProperty -name ErrorLevel -Value $matches[1] -PassThru| Add-Member -type NoteProperty -name MinCount -Value $matches[2] -PassThru| Add-Member -type NoteProperty -name DateDemand -Value $matches[5] -PassThru | Add-Member -type NoteProperty -name isVM -Value $matches[6] -PassThru| Add-Member -type NoteProperty -name State -Value $matches[7] -PassThru | Add-Member -type NoteProperty -name TTLmin -Value $matches[8] -PassThru | Add-Member -type NoteProperty -name LicenseId -Value $matches[9] -PassThru} } | select @{N="Id";E={$_.Index}},Client,CMID,ErrorLevel,MinCount,DateDemand,isVM,State,TTLmin,LicenseId |% { new-i
@belotn
belotn / onescancsv.ps1
Created July 12, 2013 13:27
Generated 3 CSV in One scan with KMS data
get-eventlog -LogName "Key Management Service" -ComputerName "COMPUTERNAME" -InstanceId 1073754114 | select Index,Message,TimeGenerated |% {if ($_.MEssage -match ".*(0x[0-9a-f]+),(\d+),([^,]+),([0-9a-f\-]+),([^,]+),(\d),(\d),(\d+),([0-9a-f\-]+).*") { $_ | Add-Member -type NoteProperty -name Client -Value $matches[3] -Passthru | Add-Member -type NoteProperty -name CMID -Value $matches[4] -PassThru | Add-Member -type NoteProperty -name ErrorLevel -Value $matches[1] -PassThru| Add-Member -type NoteProperty -name MinCount -Value $matches[2] -PassThru| Add-Member -type NoteProperty -name DateDemand -Value $matches[5] -PassThru | Add-Member -type NoteProperty -name isVM -Value $matches[6] -PassThru| Add-Member -type NoteProperty -name State -Value $matches[7] -PassThru | Add-Member -type NoteProperty -name TTLmin -Value $matches[8] -PassThru | Add-Member -type NoteProperty -name LicenseId -Value $matches[9] -PassThru} } | select @{N="Id";E={$_.Index}},Client,CMID,ErrorLevel,MinCount,TimeGenerated,DateDemand,isVM,S
@belotn
belotn / onescan_csv_incremental.ps1
Created July 12, 2013 13:36
linked ton onescancsv.ps1 add Only events that occured after the last memorized event
get-eventlog -LogName "Key Management Service" -ComputerName "COMPUTER" -InstanceId 1073754114 -After $([datetime]::ParseExact( $(import-csv .\Leases.csv |? { $_.ServerName -eq "COMPUTER" }| select TimeGenerated | sort TimeGenerated -desc | select -First 1).TimeGenerated ,'MM/dd/yyyy HH:mm:ss', $null) ) | select Index,Message,TimeGenerated |% {if ($_.MEssage -match ".*(0x[0-9a-f]+),(\d+),([^,]+),([0-9a-f\-]+),([^,]+),(\d),(\d),(\d+),([0-9a-f\-]+).*") { $_ | Add-Member -type NoteProperty -name Client -Value $matches[3] -Passthru | Add-Member -type NoteProperty -name CMID -Value $matches[4] -PassThru | Add-Member -type NoteProperty -name ErrorLevel -Value $matches[1] -PassThru| Add-Member -type NoteProperty -name MinCount -Value $matches[2] -PassThru| Add-Member -type NoteProperty -name DateDemand -Value $matches[5] -PassThru | Add-Member -type NoteProperty -name isVM -Value $matches[6] -PassThru| Add-Member -type NoteProperty -name State -Value $matches[7] -PassThru | Add-Member -type NoteProperty -name TTLmi
@belotn
belotn / zonechange.ps1
Last active December 19, 2015 21:18
Move servers to a new zone base on their IPs
get-xaserver |? { $_.IPAddresses -match $MyIp } |? { |select ServerName,@{N="Session";E={@(get-xasession -ServerName $_.ServerName |?{ $_.State -eq "Connected" -and $_.SessionId -gt 0}).Count}} |? { $_.session -eq 0 } |%{ if( $(Get-Xaserver -Servername $_.ServerName).ZoneName -ne $newZone){ set-xaserverzone -ServerNAme $_.Servername -ZoneName $newZone; Restart-Computer $_.ServerName } }
@belotn
belotn / get-xaserverrole.ps1
Created September 10, 2013 13:24
Get XenApp Server Role
$Branch='LocalMachine'
$SubBranch="SOFTWARE\Wow6432Node\Citrix\IMA\RUNTIME"
get-xaserver | select ServerNAme,@{N="Session-Only";E={
$registry=[microsoft.win32.registrykey]::OpenRemoteBaseKey($branch,$_.servername)
$registrykey=$registry.OpenSubKey($Subbranch)
@{$true="Controller";$false="Worker"}[$registrykey.GetValue("WorkerRole") -eq 0]
}}
@belotn
belotn / get-emptygpo.ps1
Created October 4, 2013 13:10
GEt List of empty GPO require module grouppolicy
get-gpo -All |?({ $gpo = get-gporeport -Name $_.DisplayName -ReportType xml; $gpo.GPO.Computer.ExtensionData -eq $null -and $gpo.GPO.User.ExtensionData -eq $null}) | select DisplayName
@belotn
belotn / get-emptygpo2.ps1
Last active December 24, 2015 16:28
Fast Get a list of empty GPO
Get-ADObject -Filter 'ObjectClass -eq "groupPolicyContainer"' -SearchBase 'CN=Policies,CN=System,DC=fabrikam,DC=com' |% { Get-Adobject $_.distinguishedName -properties * } |?{ [bool]( gci "$($_.gPCFileSysPath)\User") -eq $false -and [bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false } | select DisplayName
@belotn
belotn / get-RequiredGpoStatus.ps1
Created October 7, 2013 13:01
Get required flag for GPO
Get-ADOrganizationalUnit -Filter 'OU -like "*Citrix*"' -SearchBase 'dc=fabricam,dc=com' -Properties * |% {
$_.gpLink -split ']' } |? {
$_ -match '[0,2]$'} |% {
(($_ -replace '\[','').split(';')[0]) -replace 'LDAP://',''} |% {
get-adobject $_ -properties * } |
sort -Unique DisplayName |
select DisplayName,flags,@{N='flagsRecommended';E={
if([bool]( gci "$($_.gPCFileSysPath)\User") -eq $false){
if([bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false){
3
@belotn
belotn / get-requiredGPOgFlag1L.ps1
Last active December 24, 2015 21:39
Get require GPO Flags one liner
Get-ADOrganizationalUnit -Filter 'OU -like "*Citrix*"' -SearchBase 'dc=fabricam,dc=com' -Properties * |% { $_.gpLink -split ']' } |? { $_ -match '[0,2]$'} |% {(($_ -replace '\[','').split(';')[0]) -replace 'LDAP://',''} |% { get-adobject $_ -properties * } | sort -Unique DisplayName | select DisplayName,flags,@{N='flagsRecommended';E={if([bool]( gci "$($_.gPCFileSysPath)\User") -eq $false){if([bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false){3}else{ 1}}else {if([bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false){ 2}ELSE{ 0}} } }