Jere's Techblog

Blog CONTENTS

We are drowning in information, but starved for knowledge. - John Naisbitt

Cloud

This area is all about private cloud, SaaS,IaaS,PaaS but also about solutions like Nextcloud,OwnCloud,Seacloud,OneDrive

Linux

If you want to know more about the OpenSource Penguin, you've come to the right place. Learn more about what you can do with the OS from the 90s

Network

Network professional? I'm sure I'm not, but I'm sure you'll find some hints about useful tools. Or maybe you just want to use a SSH service as proxy, tunnel.

Scripting & Programming

A large part of this blog area is about Powershell, but in the future there will be more content like SQL,C#,VBS,.Net etc. as well.

Web

HTML5, CMS, CSS and respsonsive are all unfamiliar terms? Then this is the right place for you, I am not a webprofessional, but I can give some start tips to the newbies.

Windows

With over 80% market share, Windows is the world's leading operating system. Tips & tricks, tutorials, troubleshooting and much more can be found in this section.

Citrix

It's all about Terminal Services, NetScaler, VDI, XenApp, XenDesktop, StoreFront, CitrixDirector and Citrix Delivery Controller.

Hypervisor

Hypervisors, where our virtual machines are hosted. Installation Guides, Comparisons, Configurations and more..

news

Rename vLan PowerCLI

This script changes the vLan name of each network adapter within a vCenter.
The script works with PowerCLI (tested with version 6.0 /6.5).

The following variables should be adjusted in the script.
$vcserver = “Specify FQDN.of.vcenter.”.
$VPGName = “Specify the current vLan name”.
$VPGNameNew = “Specify the new vLan name”.

# by Jeremias Kühnis
#check if vmware modules are loaded
function checkmodule {

    If (!(Get-PSSnapin * | where { $_.Name -eq 'VMware.VimAutomation.Core'})) {Add-PSSnapin *}


        if (-not (Get-PSSnapin -Name 'VMware.VimAutomation.Core')) {
            write-host "VMWare PSSnapin is not loaded - PSSession/Windows will be closed in 10 seconds" -backgroundcolor "Yellow" -ForegroundColor "red"
            sleep 10
            exit
            }
        else{
        Write-Host "VMWare PSSnapin loaded" -ForegroundColor "Green"
        }
}

# VCenter you are connecting too
function connectserver{

    $vcserver= 'any.vCenter.FQDN'
    Connect-VIServer $vcserver
}

function renamevpg{
# Change VirtualPortGroup / VLANS
    $VPGName = 'XD_2011' # Variable Vlan
    $NewVPGName ='XD_2011_new'#Variable new VLAN Name

    #Set the name of the "Standard-Virtual Switch"
    $VPG = Get-VirtualPortGroup -Name $VPGName
    Set-VirtualPortGroup -VirtualPortGroup $VPG -Name $NewVPGName
    Start-Sleep 30
   # Loop to make changes to new Network Adapter

    ForEach ($adapter in (Get-NetworkAdapter * | where {$_.NetworkName -eq $VPGName})){
    Set-NetworkAdapter -NetworkAdapter $adapter -NetworkName "$NewVPGName" -Confirm:$false
    Write-Host $adapter
    }
}

checkmodule
connectserver
renamevpg

vertical Cursor selection

Perhaps you remember the moment when you found out that you can replace the text at the cursor position with the “Insert” key and that it will no longer insert the text but overwrite it at this position.
This was a WOW-effect for me “finally I know how to switch off this stupid function”. With regard to users who work exclusively or very much with the keyboard; as in the old DOS times or today on Linux (with editors like vim /nano) this makes sense.
I’m always amazed that there are users who don’t know this. If they accidentally press the key, they restart the PC to fix this “error”.

But there is one more thing that only a few people know.
After all, the nice thing about IT is that you never stop learning and you learn every day something new.

About 5 years ago I asked myself how I could remove the first character on every line from a list.
The list had about 4000 characters…so a manual intervention was out of the question.
I thought: “There are some ways to do this, e.g. with a simple loop script or by concatenating characters/words in Excel”.
But to be honest my script/programming knowledge was virtually non-existent at that time and I didn’t have time for the Excel crafting either…it had to be an easy way, because it was an important file that had to be edited fast.

Then I asked myself if you could simply mark “vertically” with the mouse cursor and delete the corresponding character.

Google gave me the answer!
Since then I use this method very often to edit files.

And now for the trick:
SHIFT + ALT” with the arrow keys “UP/Down” serve as navigation for the vertical marking.

Unfortunately not all programs/editors support this (e.g. the normal Windows Notepad program can’t do this).

I have successfully tested this function with the following programs:

 

  • Atom Editor
  • Notepad++
  • Powershell_ISE
  • Atom Editor
  • Visual Studio
  • Visual Studio Code (depending on the user/profile setting).

It is also possible to mark whole blocks by using the arrow keys “SHIFT + ALT” & “UP/Down + Left/Right”.

Example “Block Selection” in Notepad++:

By

Read More

Compare AD-GroupMember

Example:

JKCompare-ADGroupMemeber -Group1 GROUPNAME1 -Group2 GROUPNAME2

Optional Parameter:

-IncludeEqual yes

#13.11.2018 Jeremias Kühnis

Function JKCompare-ADGroupMemeber{
[CmdletBinding()]
Param(
    [Parameter(Mandatory=$true)]
    [string]$Group1,
    
    [Parameter(Mandatory=$true)]
    [string]$Group2,

    [Parameter(Mandatory=$false)]
    [ValidateSet("yes", "no")]
    [string]$IncludeEqual
)

IF($IncludeEqual -eq "Yes"){
    diff (Get-ADGroupMember $Group1) (Get-ADGroupMember $Group2) -Property 'SamAccountName' -IncludeEqual
}Else{
    diff (Get-ADGroupMember $Group1) (Get-ADGroupMember $Group2) -Property 'SamAccountName'
}

Write-Host "#############################################" -ForegroundColor Cyan
Write-Host "== This user is in both groups (If option is enabled)."
Write-Host "=> This user is in the second group ($group2)."
Write-Host "<= This user is in the first group ($group1)."
Write-Host "#############################################" -ForegroundColor Cyan
}

By

Read More

Remove AD-Group on certain Users

This script is very handy in dayli business, when you need to remove multiple users from an AD-Group.

In the userlist the users can be specified with the samAccountName.

Of course there is the possibility to fill “$UserList” variable with a list e.g. a CSV-File. In this case you can Use the function “Import-Csv” which is an out of the Box Powershell feature.

#13.11.2018 by Jeremias Kühnis
#Remove AD-Groupmemership

$ADGroup = "someAdGroupName"

$Userlist = @(
"SamAccountName1"
"SamAccountName2"
"SamAccountName3"
)

$Userlist | % {Remove-ADGroupMember -Identity $ADGroup -Members $_ -Confirm:$false}

By

Read More

Bulk reboot Server with PowerCLI

Tested with PowerClI Version 6.5

This script allows you to restart an array of servers trough PowerCLI.
You will be prompted to specify your ESXi-Host /vCenter Environment. Ensure that you enther the FQDN.

The script will reboot your servers without confirmation.

#13.11.2018 Restart a list/array of Servers through vCenter/Powercli
 
IF(!(Get-Module vm* | where { $_.Name -eq 'VMware.VimAutomation.Core'})){
       (Get-Module –ListAvailable VMware.VimAutomation.Core | Import-Module)
         if (-not (Get-Module -Name 'VMware.VimAutomation.Core')){
               Write-Warning "Could not find/load 'PowerCLI Module.  Ensure that you are running this Script on Server with PowerCLI."
               return
         }
}

 
Write-Host "####################################" -ForegroundColor Yellow
$vCenter = Read-Host -prompt "Please enter the Name of your ESXi Host or vCenter" 

Connect-VIServer $vCenter
$server = @(
# Enter Servernames here -> Equivalent to the Name of the VM-Target                   
"Hostname-Server1"
"Hostname-Server2"
"Hostname-Server3"
)
 
 
foreach ($server in $server){
    try{
        Restart-VM -VM $server -Confirm:$false
        write-host "Reboot OK $server" -ForegroundColor Green
    }catch{
        write-host "Reboot NOT OK $server" -ForegroundColor yellow
          }
}

Disconnect-VIServer -Server $vCenter -Confirm:$false

Bulk reboot Server

With this variant, the servers from a list or an array will be restarted sequentially. If a server is not reachable or has problems with the Windows-Remoting-Service, this can lead to long runtimes. It gives you a nice overview where the reboot job worked or not.

With the parameter “-force” the servers will be rebooted even if there is still an active user session.

#13.11.2018 Restart a list/array of Servers through Windows Remoting

$server = @(
"Hostname-Server1"
"Hostname-Server2"
"Hostname-Server3"
)


foreach ($server in $server){
    try{
        Restart-Computer -ComputerName $Server -force
        write-host "Reboot OK $server" -ForegroundColor Green
    }catch{
        write-host "Reboot NOT OK $server" -ForegroundColor yellow
          }

}

This is the parallel way to reboote servers from a list/array as a job using the “Invoke” function.

#13.11.2018 Restart a Liste/Array of Servers through Windows Remoting

$server = @(
"Hostname-Server1"
"Hostname-Server2"
"Hostname-Server3"
)


foreach ($server in $server){
Invoke-Command -ComputerName $Server -ScriptBlock {shutdown -r -f -t 1} -AsJob  
}

With this function you can check if the servers have been restarted. You can also Check the last boot time.

#13.11.2018 Restart a Liste/Array of Servers through Windows Remoting

$array = @()
$server = @(
"HostnameServer-1"
"HostnameServer-2"
"HostnameServer-3"
)

foreach ($server in $server){

    IF($s= New-CimSession -ComputerName $server -ErrorAction SilentlyContinue){
        $array += (Get-CimInstance -ClassName win32_operatingsystem -CimSession $s ) #| select csname, lastbootuptime
    }Else{
        $myObject = [PSCustomObject]@{
            PSComputerName     = $server
            csname     = $server
            lastbootuptime = 'no data retrieved'
            }
        $array += $myObject
    }
}

Function Checkreboottime{

Param(
  [Parameter(Mandatory=$true)]
   [int]$time
)


$TimeNow = Get-Date

$array | % {
    IF(!($_.lastbootuptime -eq "no data retrieved")){
        IF ([dateTime]$_.lastbootuptime.AddMinutes($time) -ge $TimeNow){
            write-host $_.csname $_.lastbootuptime -ForegroundColor Green
        }Else{
            write-host $_.csname $_.lastbootuptime -ForegroundColor yellow
        }
    }Else{
        write-host $_.csname $_.lastbootuptime -ForegroundColor Cyan
        }
    }

}

After calling the script, the function “Checkreboottime” can be used to check which servers have been restarted within a certain time.

Example: Checkreboottime -time 1000

The value 1000 indicates the minutes.

Yellow = Computer has not been restarted for more than 1000 minutes (since the time the script was executed)

Blue= No values could be determined

Green= computer restarted within 1000 minutes (since the script was executed)

By

Read More

GPUpdate on all Worker Machines

This Script will invoke an “GPupdate /force”  command on all CitrixWorker Machines.

#12.03.2018 Jeremias Kühnis Updates GPO on all Workermachines
#Ensure that you are running this Script on a Citrix DeliveryController, otherwise you have to enter an Adminadress like '(Get-BrokerMachine -AdminAddress "FQDN of your DeliveryController").DNSName'  (modify Line 13)


IF(!(Get-PSSnapin -Name "Citrix.Broker.Admin.V2" -ErrorAction SilentlyContinue)){
    Add-PSSnapin *
        IF(!(Get-Command -Name "Get-BrokerMachine" -ErrorAction SilentlyContinue)){
         Write-Warning "Could not find/load CitrixPSSnapin 'Citrix.Broker.Admin.V2' or the Cmdlet 'Get-BrokerMachine' is not available. Ensure that you are running this Script on a DeliveryController Server."
         return
        }
    }

(Get-BrokerMachine).DNSName | % {
      Invoke-Command -ComputerName $_ -ScriptBlock {gpupdate /force} -AsJob  
}

Get-Job

By

Read More