Skip to main content

PowerShell

Making a remote PowerShell connection

·2 mins
In this article I will make a short description how to make a remote PowerShell connection. I needed this for a job once, tried to make a remote PowerShell connection from a Non Domain Joined machine to a Domain Joined server. I needed to re-configure the server first before making a connection. With the following code you can try and test the connection:

Create offline backups of the NetScaler config

··8 mins
I’ve created a PowerShell script that can be used to generate an (offline) backup of a Citrix NetScaler. If you want you can use the supplied batchfile for example to schedule the backup in Scheduled Tasks to run everyday. Some more information about the parameters used:

Generate an Let's Encrypt certificate what can be used on the NetScaler

··1 min
Edit 07-04-2017: Check out my new and updated version! I’m trying to create an (PowerShell) script to automate the Let’s Encrypt certificate creation. Specifically for the Citrix NetScaler. Currently still Work In Progress… It’s not yet finished. The prerequisite is that you have a configured NetScaler (http) Content Switch vServer. The script will present you with the required configuration rules (it will also be copied to your clipboard so you only have to copy it in the cli of the NetScaler) For the meantime you can find it on GitHub: GenCertForNS on GitHub More soon (I hope)…

Remove AppX (Modern) Apps

·2 mins
With the following PowerShell script you can remove AppX Apps in Windows 8(.1) and 10. Note: The apps will be removed for the Current and New users only! <# To skip a AppX app while removing change "Remove" to "NoChange", the app will not be removed. #> $arrAppxApps = @() $arrAppxApps += ,@('Remove','6.4|10.0','*3DBuilder*') # Uninstall 3D Builder $arrAppxApps += ,@('Remove','6.4|10.0','*Appconnector*') # Uninstall $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*bingfinance*') # Uninstall Money $arrAppxApps += ,@('Remove','6.2|6.3','*BingFoodAndDrink*') # $arrAppxApps += ,@('Remove','6.2|6.3','*BingHealthAndFitness*') # $arrAppxApps += ,@('Remove','6.2|6.3','*BingMaps*') # $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*bingnews*') # Uninstall News $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*bingsports*') # Uninstall Sports $arrAppxApps += ,@('Remove','6.2|6.3','*BingTravel*') # $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*bingweather*') # Uninstall Weather $arrAppxApps += ,@('Remove','6.2|6.3','*Camera*') # $arrAppxApps += ,@('Remove','6.2|6.3','*OneDrive*') # $arrAppxApps += ,@('Remove','6.4|10.0','*getstarted*') # Uninstall Get Started $arrAppxApps += ,@('Remove','6.2|6.3','*HelpAndTips*') # $arrAppxApps += ,@('Remove','6.4|10.0','*officehub*') # Uninstall Get Office $arrAppxApps += ,@('Remove','6.4|10.0','*solitairecollection*') # Uninstall Microsoft Solitaire Collection $arrAppxApps += ,@('Remove','6.2|6.3','*Media.PlayReadyClient.2*') # 2x $arrAppxApps += ,@('Remove','6.2|6.3','*Media.PlayReadyClient.2*') # $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*onenote*') # Uninstall OneNote $arrAppxApps += ,@('Remove','6.4|10.0','*people*') # Uninstall People $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*skypeapp*') # Uninstall Get Skype $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*photos*') # Uninstall Photos $arrAppxApps += ,@('Remove','6.2|6.3','*Reader*') # $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*windowsalarms*') # Uninstall Alarms and Clock $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*windowscalculator*') # Uninstall Calculator $arrAppxApps += ,@('Remove','6.4|10.0','*windowscamera*') # Uninstall Camera $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*windowscommunicationsapps*') # Uninstall Calendar and Mail $arrAppxApps += ,@('Remove','6.4|10.0','*windowsmaps*') # Uninstall Maps $arrAppxApps += ,@('Remove','6.4|10.0','*windowsphone*') # Uninstall Phone Companion $arrAppxApps += ,@('Remove','6.2|6.3','*WindowsReadingList*') # $arrAppxApps += ,@('Remove','6.4|10.0','*soundrecorder*') # Uninstall Voice Recorder $arrAppxApps += ,@('Remove','6.2|6.3','*WindowsScan*') # $arrAppxApps += ,@('Remove','6.4|10.0','*windowsstore*') # Uninstall Store $arrAppxApps += ,@('Remove','6.4|10.0','*xboxapp*') # Uninstall Xbox $arrAppxApps += ,@('Remove','6.2|6.3','*XboxLIVEGames*') # $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*zunemusic*') # Uninstall Groove Music $arrAppxApps += ,@('Remove','6.2|6.3|6.4|10.0','*zunevideo*') # Uninstall Movies & TV Write-Host -ForegroundColor White "Removing Appx Apps" Write-Verbose '' foreach ($AppxApp in $arrAppxApps) { Write-Host -NoNewline -ForegroundColor Gray " -" $AppxApp[2] Switch ($AppxApp[0]) { "NoChange" { Write-Host -ForegroundColor Yellow " (skipped) No changes made" } "Remove" { if ($AppxApp[1] -Match ($varWinVer)) { Try { Get-AppxPackage | Where-Object {$_.PackageFullName -like $AppxApp[2]} | Remove-AppxPackage -ErrorAction SilentlyContinue | Out-Null Get-AppxPackage -allusers | Where-Object {$_.PackageFullName -like $AppxApp[2]} | Remove-AppxPackage -ErrorAction SilentlyContinue | Out-Null Get-AppxProvisionedPackage -Online | Where-Object {$_.packagename -like $AppxApp[2]} | Remove-ProvisionedAppxPackage -Online -ErrorAction SilentlyContinue | Out-Null } Catch { Write-Host -ForegroundColor Red (" (error)") $FailedItem = $_.Exception.ItemName Write-Verbose ('Caught an error') Write-Verbose ('ErrorMessage: ' + $ErrorMessage) Write-Verbose ('FailedItem: ' + $FailedItem) continue } Finally { Write-Host -ForegroundColor Green (" (done)") } } Else { Write-Host -ForegroundColor Yellow " (skipped) not applicable to this OS" } } } }

OptimizeEndpoint

·1 min
I’ve been using my “Windows optimize script” for a while now. Most issues are resolved and it’s been tested thoroughly. So I thought why not give it back to the community, so here it is: OptimizeEndpoint. It can be used to optimize Windows 7, 8, 8.1 and 10. (It can also be used for Windows Server versions, but this is not tested) I used the script made by Ingmar Verheij, and made some changes. It contains most of the Citrix XenDesktop Best Practices. Please don’t run the script without reviewing the options, it can damage you master image if you’re not careful! At the top of the image there are some parameters that can be set. Read the comments. Run it on your own risk. If you have issues or questions let me know.

CtxVdDrain Script

·1 min
I released also my CtxVdDrain Script, this script will put any selected XenDesktop Machine catalog in maintenance mode and turn it of where possible. It won’t kick users out of their desktops, it will wait and try again. You can download it here

CtxVdContinuousShutdown Script

·1 min
For a customer we needed a solution to recycle “old” PVS Virtual Desktops. And because Citrix XenDesktop doesn’t use the oldest desktops first (without using power options), we had to come up with a solution. And so my Shutdown Script was born. The script basically checks which Virtual Machines are the oldest, puts them in maintenance mode so no user can use it anymore. After this is done the vm’s are given a shutdown command. When their down , maintenance mode will be turned off. You can get it here.

CtxVdStatus Script

·1 min
Today I decided to put my CtxVdStatus script on GitHub. With this script you can get an overview of your Citrix XenDesktop environment. It helped me to troubleshoot some issues. You can download/view it here

Powershell Gui Basic

·2 mins
#PUT XAML BELOW between the @" "@ $inputXML = @" <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication1" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> </Grid> </Window> "@ $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window' [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') [xml]$XAML = $inputXML #Read XAML $reader=(New-Object System.Xml.XmlNodeReader $xaml) try{ $Form=[Windows.Markup.XamlReader]::Load( $reader ) }catch [System.Management.Automation.MethodInvocationException] { Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..." write-host $error[0].Exception.Message -ForegroundColor Red if ($error[0].Exception.Message -like "*button*"){ write-warning "Ensure your &lt;button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n" } }catch{ Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." } #=========================================================================== # Store Form Objects In PowerShell #=========================================================================== $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)} Function Get-FormVariables{ if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true} write-host "Found the following interactable elements from our form" -ForegroundColor Cyan get-variable WPF* } Get-FormVariables #=========================================================================== # Use this space to add code to the various form elements in your GUI #=========================================================================== #Reference #Adding items to a dropdown/combo box #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"}) #Setting the text of a text box to the current PC name #$WPFtextBox.Text = $env:COMPUTERNAME #Adding code to a button, so that when clicked, it pings a system # $WPFbutton.Add_Click({ Test-connection -count 1 -ComputerName $WPFtextBox.Text # }) #=========================================================================== # Shows the form #=========================================================================== write-host "To show the form, run the following" -ForegroundColor Cyan '$Form.ShowDialog() | out-null' Source

Basic PowerShell start

·1 min
<# .SYNOPSIS A summary .DESCRIPTION A more in depth description .NOTES Additional Notes File Name : xx.ps1 Author : First Last - e@mail.com Requires : ... .LINK A hyper link .EXAMPLE The first example .EXAMPLE The second example .PARAMETER xxx text #> [CmdletBinding()] param ( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)][int64] $xxx=42 ) #Script