SHIFT-WIKI - Sjoerd Hooft's InFormation Technology
This WIKI is my personal documentation blog. Please enjoy it and feel free to reach out through blue sky if you have a question, remark, improvement or observation.
Scripts: PowerCLI: Detect and Change Guest Selected OS
Summary: How to bulk change the guest selected OS in your VMware VMs.
Date: Around 2017
Refactor: 21 February 2025: Checked links and formatting.
The Guest Selected OS is the VM value to determine how the VMware Tools should work. If this setting is not correct then weird issues may occur on your VMs from errors and BSOD to performance issues. These scripts will help you correct this issue:
Manually this can be done like this, but be aware that the VM needs to be turned off:
- In the vSphere Client inventory, right-click the virtual machine and select Edit Settings.
- Click the Options tab and select General Options.
- Select a guest operating system type and version.
- Click OK to save your changes and close the dialog box.
But scripted everything can be done automatically, which is useful when a lot of VMs are configured wrong.
Make an Overview
# Make an overview of all VMs that have the wrong OS configured ForEach ($VM in (Get-VM)){ $vmview = Get-VM $VM | Get-View $GuestFamily = $vmview.Guest.GuestFamily $GuestSelectedOS = $vmview.Summary.Config.GuestFullName $GuestRunningOS = $vmview.Guest.GuestFullname if (($GuestFamily -eq "windowsGuest") -and ($GuestSelectedOS -ne $GuestRunningOS)){ # Choose your output: The first will give you a pretty but further useless output, the second one can be used to save as a cvs file, and the third can be directly used as input in the next script. #Write-Host "VM = $VM `n`t Guest Family = $GuestFamily `n`t Set OS = $GuestSelectedOS `n`t Running OS = $GuestRunningOS" #Write-Host "$vm,$GuestFamily,$GuestSelectedOS,$GuestRunningOS" #Write-Host "$vm" } }
Change the Guest Selected OS
# Change the Guest selected OS for all VMs from an inputfile ## The inputfile needs to have one VM per line ## The VM will be turned off, and this will be checked before the change is made ## Afterwards the VM will be started again # Start directory for the input file $startdir = "D:\sjoerd" # Creating Source List $sourcename = "$startdir\inputfile.txt" $vms = Get-Content $sourcename | Foreach-Object {Get-VM $_ } # Scipt functions # Note that you can suppress output from commands using | Out-Null Function logger ($message) {Write-Host -ForegroundColor Green (Get-Date -format "yyyyMMdd-HH.mm.ss") `n "$message" `n} Function loggeralert ($message) {Write-Host -ForegroundColor Red (Get-Date -format "yyyyMMdd-HH.mm.ss") `n "$message" `n} Function PowerOn-VM($vm){ Start-VM -VM $vm -Confirm:$false -RunAsync | Out-Null logger "$vm is starting!" sleep 5 $time = 1 # Now check if the VM is started within 120 loops with each 5 seconds of waittime do { $vmview = Get-VM $VM | Get-View $getvm = Get-VM $vm $powerstate = $getvm.PowerState $toolsstatus = $vmview.Guest.ToolsRunningStatus logger "$vm is starting, powerstate is $powerstate and toolsstatus is $toolsstatus!" sleep 5 $time++ # Adjust the timer $time to wait longer or shorter for the VM to start up. Lowering this value will not break anything, you'll just have to check manually whether the VM started successfully. }until((($powerstate -match "PoweredOn") -and ($toolsstatus -match "guestToolsRunning")) -or ($time -eq 2)) if ($toolsstatus -match "guestToolsRunning"){ logger "$vm is started and has ToolsStatus $toolsstatus" } else{$Startup = "ERROR"} return $Startup } Function PowerOff-VM($vm){ Shutdown-VMGuest -VM $vm -Confirm:$false | Out-Null Logger "$vm is stopping!" sleep 5 $shutdown = "starting" $time = 1 # Now check if the VM is shutdown in 60 loops with each 5 seconds of waittime, and if not perform a hard shutdown do { $vmview = Get-VM $vm | Get-View $getvm = Get-VM $vm $powerstate = $getvm.PowerState $toolsstatus = $vmview.Guest.ToolsStatus logger "$vm is stopping with powerstate $powerstate and toolsStatus $toolsstatus!" sleep 5 $time++ if($time -eq 60){ loggeralert "$vm is taking more than 5 minutes to shutdown. Hard powering off the VM." Stop-VM -VM $vm -Confirm:$false | Out-Null } }until(($powerstate -match "PoweredOff") -or ($time -eq 120)) if ($powerstate -match "PoweredOff"){ logger "$vm is powered-off" } else{$shutdown = "ERROR"} return $shutdown } # Handle each VM foreach($item in $vms){ $vm = $item.Name # ForEach ($VM in (Get-VM)){ $vmview = Get-VM $VM | Get-View $GuestFamily = $vmview.Guest.GuestFamily $GuestSelectedOS = $vmview.Summary.Config.GuestFullName $GuestRunningOS = $vmview.Guest.GuestFullname if (($GuestFamily -eq "windowsGuest") -and ($GuestSelectedOS -ne $GuestRunningOS)){ #logger "VM = $VM `n`t Guest Family = $GuestFamily `n`t Set OS = $GuestSelectedOS `n`t Running OS = $GuestRunningOS" #logger "$vm,$GuestFamily,$GuestSelectedOS,$GuestRunningOS" if ($GuestRunningOS -eq "Microsoft Windows Server 2008 R2 (64-bit)"){ $poweroff = PowerOff-VM $vm if ($poweroff -ne "ERROR"){ Get-VM $vm | Set-VM -GuestId "windows7Server64Guest" -Confirm:$false PowerOn-VM $vm } } } }
Change Expired AD Password
Summary: How to change your own expired password when you can’t login to RDP.
Date: Around 2022
Refactor: 21 February 2025: Checked links and formatting.
I often have multiple accounts to keep track of, with various password policies. Sometimes a password just expires and I don't want to bother support staff to reset it to a temporary password which I have to reset then again. It's a lot of hassle. To prevent that, I became a big fan of the PowerShell function below. All credits go to Evotec, but I've used it a lot. If you're on a personal system, you could just simply do:
Install-Module PSSharedGoods -Force Set-PasswordRemotely
But if you're on a server system without internet access or do not want to install form unknown sources you could simply paste the function into your powershell session and then run the function:
function Set-PasswordRemotely { [CmdletBinding(DefaultParameterSetName = 'Secure')] param( [Parameter(ParameterSetName = 'Secure', Mandatory)][string] $UserName, [Parameter(ParameterSetName = 'Secure', Mandatory)][securestring] $OldPassword, [Parameter(ParameterSetName = 'Secure', Mandatory)][securestring] $NewPassword, [Parameter(ParameterSetName = 'Secure')][alias('DC', 'Server', 'ComputerName')][string] $DomainController ) Begin { $DllImport = @' [DllImport("netapi32.dll", CharSet = CharSet.Unicode)] public static extern bool NetUserChangePassword(string domain, string username, string oldpassword, string newpassword); '@ $NetApi32 = Add-Type -MemberDefinition $DllImport -Name 'NetApi32' -Namespace 'Win32' -PassThru if (-not $DomainController) { if ($env:computername -eq $env:userdomain) { # not joined to domain, lets prompt for DC $DomainController = Read-Host -Prompt 'Domain Controller DNS name or IP Address' } else { $Domain = $Env:USERDNSDOMAIN $Context = [System.DirectoryServices.ActiveDirectory.DirectoryContext]::new([System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Domain, $Domain) $DomainController = ([System.DirectoryServices.ActiveDirectory.DomainController]::FindOne($Context)).Name } } } Process { if ($DomainController -and $OldPassword -and $NewPassword -and $UserName) { $OldPasswordPlain = [System.Net.NetworkCredential]::new([string]::Empty, $OldPassword).Password $NewPasswordPlain = [System.Net.NetworkCredential]::new([string]::Empty, $NewPassword).Password $result = $NetApi32::NetUserChangePassword($DomainController, $UserName, $OldPasswordPlain, $NewPasswordPlain) if ($result) { Write-Host -Object "Set-PasswordRemotely - Password change for account $UserName failed on $DomainController. Please try again." -ForegroundColor Red } else { Write-Host -Object "Set-PasswordRemotely - Password change for account $UserName succeeded on $DomainController." -ForegroundColor Cyan } } else { Write-Warning "Set-PasswordRemotely - Password change for account failed. All parameters are required. " } } }
Set-PasswordRemotely
Install and Configure Dokuwiki
Summary: This wiki page shows how I installed and configured this site using dokuwiki.
Date: 2 December 2024
Installation and Basic Configuration
The original installation was already done in 2012 using the “Adore Belle” edition. In 2021 I had to do the installation again because everything broke due to a failed installation. This is the installation as from then:
- Download
- 2020-07-29 “Hogfather”
-
- Unpack the distribution tarball and upload/copy the files to the httpdocs folder
- Open the install.php in your browser and follow the instructions
- Wiki name: SHIFT
- Initial ACL policy: Public, read for everyone, write and edit for registered users only
- License: GNU Free Documentation License
- Deleted the install.php
- Configure webserver and dokuwiki
- Use nice URLs through rewriting
- Enable in Configuration Settings → Advanced Settings → Use Nice URLs: .htaccess
- Modify htaccess.dist to htaccess and uncomment rewrite rules:
## Uncomment these rules if you want to have nice URLs using ## $conf['userewrite'] = 1 - not needed for rewrite mode 2 RewriteEngine on # RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L] RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L] RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L] RewriteRule ^$ doku.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) doku.php?id=$1 [QSA,L] RewriteRule ^index.php$ doku.php
- Adjusted license to GNU Free Documentation License
Side Bar
A side bar is not included by default, but just create a page called 'sidebar' and the sidebar will be shown on the right side of the page. The sidebar is included in the template and is shown on every page.
- Create the page sidebar
Additional Configuration
I've configured the following settings:
- Basic Settings
- Tagline: — Sjoerd Hooft's InFormation Technology —
- Display Setting
- Use first heading for pagenames = Always
- Authentication Settings
- Disable DokuWiki Actions: Register
- Editing Settings
- Automatically save a draft while editing: no
- Allow embedded HTML: yes
- Link Settings
- Target window for external links: _blank
- Media Settings
- JPG compression quality (0-100): 100
Plugins
I've installed and configured the following plugins:
- Creole plugin
-
- Go to admin → Configuration Settings → Plugin Settings → Creole Plugin → Markup precedence and set this to Creole
- Creole is used to support more common wiki syntax, like the headers and tables syntax I use
-
- Tag plugin
- Requires pagelist plugin: http://www.dokuwiki.org/plugin:pagelist
- Formatting flags for the taglist: table,header,tags
- Show toolbar icon: on
- Choose style applied to pages' tags list: optimized for tags list on top of page
- Used for the tags on top of the page
- Pagelist plugin
-
- show heading line: on
- The Pagelist Plugin takes a list of wiki pages and provides a nicely formatted table with information about them.
-
- Cloud plugin
- Used for the tag cloud on the side page
- Changes plugin
- Used for the recently changed pages in the sidebar
- Blog and include plugin
-
- Position of the new entry form: none
- Used for the three most recently added pages to the start page
-
- Remove old files plugin
- Run this plugin to remove old files and clear up space
- Searchindex manager
- Used to rebuild the index search and tags
- Upgrade plugin
- Used to upgrade the wiki
- copy2clipboard Plugin
- Enables a 'copy to clipboard' button for code blocks
- htmlok plugin
- Allows (again) for native HTML and php
- Go to settings → Plugins → htmlok → Allow embedded HTML
- Wrap plugin
- Used for the boxes on the page
- Imagebox plugin
- Used to add a border around images, also supports caption markup
- Adwords
- From google adsense, list your site, get it approved and from the Ads section get the code to add it to the plugin settings
- Then edit your site listing in adsense and check the settings and then apply for the ads to be shown
- Redirect pages
- To redirect old pages to new pages or the homepage. Find all pages in the repo that do this by searching for
~~REDIRECT>
. The plugin gives a 301 http status code, which will not impact your ranking in any SEO.
Change the Logo and FavIcon
Dokuwiki checks a few places for the favicon and logo, and one of them is the root of the wiki namespace:
- Open the media manager
- Select the wiki namespace
- Select the logo.png, apple-touch-icon.png and favicon.ico and upload the files
- Add the favicon.ico also to the root of the httpdocs folder
Template Changes
Create the following file conf/tpl/dokuwiki/style.ini
to be able to make changes to the template.
Add the following lines to change the width of the site and the sidebar:
[replacements] __site_width__ = "95%" __sidebar_width__ = "25%"
Upgrade Dokuwiki
Create a backup
Create a backup by downloading the following folders:
- data/pages - contains your current pages
- data/attic - all the old versions of your pages
- data/meta - contains meta information about your pages (like who created it originally, who subscribed to it, …)
- data/media - contains your current media (images, PDFs, …)
- data/media_attic - all the old versions of your media
- data/media_meta - meta data for the media
- conf - the configuration settings
- lib - will backup the installed plugins and templates (many optional, otherwise they will need to be manually downloaded again in a possibly broken interface) However, take care not to overwrite the default included core plugins
Upgrade
Upgrading dokuwiki is best done using the Upgrade plugin. Go to the admin section and click 'Wiki Upgrade'. This will start the upgrade, by just following the steps.
Upgrade Plugins
Go to the admin section and click 'Extension Manager'. This will show you the plugins that need to be updated. Click 'Update' to update the plugins.
Useful Links
Boot Solaris x86 Into Single User Mode
Summary: How to boot solaris into single user mode.
Date: Around 2014
Refactor: 20 February 2025: Checked links and formatting.
During testing with AD LDAP Authentication for Solaris I managed to get myself locked out of the system, because of errors in the pam.conf file. I used this method to boot into single user mode so I could undo the changes in the configuration file:
- At the “GRUB” boot menu where you get the boot options press “e” to edit the boot line before the prompt times out.
- Use the arrow keys to highlight the line that starts with “kernel”
- Press “e” again to edit the line.
- Add “ -s” to the end of the line and press <ENTER>
- Press “b” to boot