Skip to content

Instantly share code, notes, and snippets.

@markgodiy
markgodiy / PsGUI_xaml_datagrid_tutorial.md
Last active April 22, 2023 16:16
Powershell XAML GUI tutorial with Datagrid, Textbox, Button, Labels
@markgodiy
markgodiy / James_PrinterMapper
Created April 4, 2023 17:42
James_PrinterMapper
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600, 400)
############################################## Start functions
# Function to return the name of the selected snaphsot from the second DropDown box
$Global:PrintServer = ""
function FetchPrinters {
$printerTxtFileLocation = 'C:\Temp\PrinterList.txt'
# $Global:PrintServer = $Global:DropDownBox1.SelectedItem.ToString()
Get-Printer -ComputerName "bamcpsvip" | where {$_.Name -like "bamc_h_lab*"} | Select-Object -ExpandProperty Name | Sort-Object -CaseSensitive | Out-File "$printerTxtFileLocation" -Force
Function ZebraTCPClient {
<#
Source/Crecit: Sven Sperner, https://github.com/sperner
Original Code Permalink:
https://github.com/sperner/PowerShell/blob/8c661ec4d0914b02095ffabb7c9dcbd8b1f0185a/TcpClient.ps1
.DESCRIPTION
-To use, load function into a powershell session console.
-Default port is 9100. Zebra printers also uses port 6101.
function Set-Lab-RemoteHostsFile {
<#
.EXAMPLE
Set-Lab-RemoteHostsFile -ComputerName <RemoteHostname> -InsertIP "214.47.x.x" -InsertDescription "RemoteServer"
#>
param(
[string]$ComputerName,
@markgodiy
markgodiy / DblClick-Execute-Powershell.wsf
Last active January 13, 2023 23:03
Write PowerShell code within a windows scripting file (.wsf) script. Useful for PowerShell GUI, and scripts that do not require elevated privileges.
<script language="VBScript">
'<![CDATA[
'// CDATA encapsulation is required for powershell to parse this file correctly as XML
'CreateObject("WScript.Shell").Run "powershell -noexit -windowstyle hidden -command ""([xml](Get-Content '" & WScript.ScriptFullName & "')).job.powershell | Invoke-Expression"""
If CreateObject("WScript.Shell").Run("powershell -noexit -command ""([xml](Get-Content '" & WScript.ScriptFullName & "')).job.powershell.'#cdata-section' | Invoke-Expression""",2, False) Then
MsgBox "Script failed to run."
End If
@markgodiy
markgodiy / DblClick-Execute-Powershell-UAC.vbs
Created January 13, 2023 23:00
Execute Powershell Script using VBA, with UAC for Security. To use this script as-is, .vbs file must be in the same folder as .ps1 file, then create shortcut to .vbs file as needed.
Function RunAsAdmin()
Dim objAPP
If WScript.Arguments.length = 0 Then
Set objAPP = CreateObject("Shell.Application")
objAPP.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" & " RunAsAdministrator",,"runas", 1
WScript.Quit
End If
End Function