Fitness, health and movement
Ive been discussing and thinking a lot about fitness and health the latest months. What is healthy and whats is not. What is fitness and what do you strive for when you go on the fitness path.
A lot of people seem to want to be fit, but have trouble getting there. You never get to the gym, or you start with a personal trainer for a couple of weeks, work hard but the quit.
Also society in whole seem to be going through a big health trend. I see nothing wrong with health awareness rising but I also see some troubling things.
It doesnt really seem to me like health is the main purpose of health anymore, health is more something that you want to show off to others, health is a lifestyle and an image. This also apply to fitness, its more an image that you want to give others, and an identity you want to have.
I see people discussing health and fitness and trying to get there, not because they want to eat healthy or exercise healthy. They just want the result, and get there fast.
The problems I see here is, getting there fast isnt healthy most of the times. Dropping huge amounts of body mass fast or training hard four or six times per week from a starting point of nothing isnt healthy. Youre gonna break, and fast.
Also the thing of achieving a health image just because you feel that society expects that of you, or maybe you expect that of yourself isnt very motivating or fun, at least if your not as unhealthy that you could die tomorrow of obesity.
My main thought here is around the fun part though. If you want to exercise, what a boring word by the way, try something you like. There is so many ways to move, so what stops you to move?
I think what stops me to move sometimes is the expectations of how to move. Adults are expect to walk on the pavement in and orderly fashion. We are not expected to squat on the bus station, or hang from lamp posts. But these things are really fun.
My experiment the latest year have been to see the world around me as a child would have. You never see a child stop moving, they explore everything in their surroundings, climbs, runs, walks, jumps. All basic movements we humans can do. Also they are having serious fun getting from point A to B.
This has been my way of “exercising” everytime I just let go of what exercise should look like and just take in whats around me and how I can play with it, time just flies, and I promise you, I get tired and sore as I would have been in the gym afterwards.
I realize this might not be for everyone, but go out of your comfort zone in your movement, try new things, and first of all try to find something you really enjoy, whether it is the gym, walking, dancing or climbing trees!
PS. Dont leat fear of being bad at something stop you! You should suck at something youre trying for the first time, then you know that the development potential is great and get the most growth!
DS.
Installera serverroller från xml del 2
I del 1 visade jag hur man använder en xml fil för att installera en roll via powershell, men om man vill installera samma roll på flera servrar då? En snabb get-help Install-WindowsFeature kanske kan ge en ledtråd:
Så som enklast använd ComputerName växeln och sedan exekvera kommandot flera gånger, men det är ju inte speciellt automatiserat eller speciellt snyggt.
För att automatisera processen behövs en lista på servrar från någon källa. Ett av de smidigaste sätten i PowerShell är csv filer. En CSV-fil är en vanlig textfil där alla värden är separerade av ett komma (Comma Separated Values).
Nu behöver vi ju bara ett värde, nämligen datornamn, så bara öppna notepad och mata in datornamnen, som det ska installeras roller på, enligt följande bild:
För att importera listan på servrar i PowerShell skriv import-csv servers.txt
Nu är det dags att skriva lite kod, nämligen en for-loop. Den behövs för att exekvera ett kommando för varje rad i en lista. Så först behövs listan läggas in i en variabel:
1 |
$ServerList = Import-CSV Servers.txt |
Nästa steg blir for loopen:
1 2 3 |
foreach ($Server in $ServerList) { } |
På ren svenska, för varje server i listan med servrar utför något, och något ska vara mellan måsvingarna. Och det som ska utföras är att installera en serverroll:
1 2 3 4 |
foreach ($Server in $Serverlist) { Install-WindowsFeature -ComputerName $Server -ConfigurationFilePath “c:\configfiles\DeploymentConfigTemplate.xml” } |
Enkelt eller hur? Men då frågar sig vän av ordning, om jag vill ha olika roller på olika servrar då? Ja då är det bara att lägga in den informationen i CSV-filen.
För att använda flera parametrar från CSV filen ange bara kolumnnamnet efter variabeln. Så nedan översatt från Powershell till svenska är alltså: För varje rad i listan med servrar stoppa in servernamnet i variabeln server och stoppa in XML filen i variabeln ConfigFile.
1 2 3 4 5 6 |
foreach ($Row in $Serverlist) { $Server = $Row.ServerName $ConfigFile = $Row.XML Install-WindowsFeature -ComputerName $Server -ConfigurationFilePath $ConfigFile } |
Ett lite mer komplett skript med en variabel för sökvägen till konfigurationsfilerna.
1 2 3 4 5 6 7 8 9 10 11 |
#Path to Role Configuration XML:s $Path = "C:\ConfigFiles\" $ServerList = Import-CSV Servers.txt foreach ($Row in $Serverlist) { $Server = $Row.ServerName $ConfigFile = $Path + $Row.XML Install-WindowsFeature -ComputerName $Server -ConfigurationFilePath $ConfigFile } |
Skriptet ovan är en grund för att egentligen göra vad som helst med parametrar från en textfil, bara ersätt Install-WindowsFeature med ett annat PowerShellkommando och kör. Ett exempel är mitt skript för att installera websiter från CSV.
Installera serverroller från xml
Det senaste har jag jag fått frågan från flera håll:
I server manager:n i Windows Server 2012 efter jag klickat igenom alla steg för att installera en ny server roll så kan jag välja att skapa en xml fil innehållande all konfiguration jag gjort, men jag hittar ingenstans jag kan ange att använda den?
Jo, det ska jag berätta, i PowerShell förstås!
Bara för att illustrera vilken xml fil jag pratar om så titta på följande skärmdump.
Så i sista steget kan du exportera en xml med alla inställningar du gjort under guiden.
Spara xml filen på ett lämligt ställe, i exemplet c:\configfiles\DeploymentConfigTemplate.xml
PowerShell kommandot för att installera roller och features är Install-WindowsFeature. En snabb Get-Help Install-WindowsFeature returnerar:
Alltså helt enkelt:
Install-WindowsFeature -ConfigurationFilePath “c:\configfiles\DeploymentConfigTemplate.xml”
Detta gör det strålande enkelt att installera antingen flera likadana servrar eller installera om samma server med samma konfiguration!
Quickly set new DNS servers on a certain subnet
A customer wanted to change and validate the DNS configuration on a subnet so I created this script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Script that replaces or sets a random set of DNS servers on every networkadapter with a certain default gateway. # Version 1.0 # Created by: Lars Gustavsson Knowledge Factory # Creates two variables to randomly select between. $0 = "10.0.10.10,10.0.10.11" $1 = "10.0.10.11,10.0.10.10" #Getting the IP configuration on all interfaces with a manually configured gateway. $Interfaces = Get-NetIPConfiguration | Where-Object {$_.IPv4DefaultGateway.NextHop -eq "10.0.10.254" -and $_.IPv4Address.PrefixOrigin -eq "manual"} #Looping through all the interfaces and setting the DNS servers. foreach ($interface in $interfaces){ $DNS = Get-Random -InputObject $0, $1 Set-DnsClientServerAddress -InterfaceAlias $interface.InterfaceAlias -ServerAddresses $DNS } |
Kerberos Constrained Delegation and Managed Service Accounts
Normally when working with delegation, you just set the Service Principal Name, either with Setspn or manually with an attribute editor, then just right-click the user or computer in Active Directory Users and Computers, select properties and in the delegation tab configure the options you want.
But if you select a Managed Service Account, it looks like this:
So how do you configure delegation? Simple, you need to set the correct attributes for it manually.
There are two attributes you need to modify. One of the easiest way to modify attributes is to enable advanced features in the view menu of Active Directory Users and Computers. If you then select propterties on your Managed Service Account(or any other object) you will get a simple attribute editor.
The first one is called msDS-AllowedToDelegateTo and the value here is the Service Principal Name of the service you wish to delegate to. Read more about Service Principal Names or SPN:s here.
The second one is userAccountControl. Heres where it gets just a little bit tricky. Here is where you select the options for just kerberos or any authentication protocol. The value for just kerberos is 4096, and if you want to use any authentication protocol it is 16781312.
The default value is 4128.
Here is a great article that explains these values in more detail.
http://windowsitpro.com/windows/most-confusing-dialog-box-active-directory
Automatiskt skapa websiter från CSV-fil
Följande script använder en specifierad CSV-fil som indata för att skapa upp kataloger, apppooler, samt identitet på appoolen och hostheaders.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# Script that setups several websites with apppools and directories from a configuration stored in a csv file. # Created by: Lars Gustavsson # Version: 1.1 # Changelog: 1.0 Created. # 1.1 Added creation of hostheaders and some handling of empty values in CSV. # # Instructions: # If you are running the script manually, copy all the files and subfolders to c:\temp and set the current directory to c:\temp. # Make sure to set the execution policy to unrestricted with "set-execution policy unrestricted" # Editing of local policy is done with a function done by Kyle Neier http://www.sqlservercentral.com/blogs/kyle-neier/2012/03/27/powershell-adding-accounts-to-local-security-policy/ #Setting variables #Path to CSV-File. $ACLfolder = "Folders.csv" #Importing the module for IIS administration. Import-Module webadministration #Importing function for editing local policy . .\SetLocalPrivilege.ps1 #Creating an object with the content of the CSV-file. $CreateConfig = import-csv $ACLfolder #Looping through each line in the CSV-file. ForEach ($item in $CreateConfig){ #Creating the folder specified. if ( ![string]::IsNullOrEmpty($item.FullName)){ New-Item $item.FullName -type Directory } #Creating the Application Pool and IIS-Website if ( ![string]::IsNullOrEmpty($item.AppPool)){ $apppool = "IIS:\\AppPools\" + $item.AppPool New-Item $apppool New-Item $item.VirtualDirectory -bindings $item.Binding -physicalPath $item.FullName #Modifying the site to use the Application Pool Set-ItemProperty $item.VirtualDirectory -name applicationPool -value $item.AppPool #Checking if the Application Pool should be run with a user account or with Application Pool Identity if($item.AuthType -eq "User"){ #Giving the user the right to start services Add-LoginToLocalPrivilege $item.UserName "SeServiceLogonRight" #Setting the Application Pool Identity and Settings $ChangeAppPoolUser = Get-item $apppool $ChangeAppPoolUser.processmodel.identityType = 3 $ChangeAppPoolUser.processmodel.username = $item.Username $ChangeAppPoolUser.processmodel.password = $item.AppPoolPassword $ChangeAppPoolUser.processmodel.loadUserProfile = "True" $ChangeAppPoolUser | set-item } else { Set-ItemProperty -Path $apppool -Name processmodel.identityType -Value 4 } } #Giving the application pool user modify rights to the folders. if ( ![string]::IsNullOrEmpty($item.FullName)){ $acl = Get-Acl $item.FullName $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($item.UserName, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow") $acl.AddAccessRule($rule) Set-Acl $item.FullName $acl } #Add more host headers to Website if specified in CSV if ( ![string]::IsNullOrEmpty($item.HostHeader)){ $hostheader = $item.HostHeader $binding = @{protocol="http";bindingInformation="*:80:$hostheader"} New-ItemProperty $item.VirtualDirectory -Name Bindings -Value $binding } } |
Skapa en CSV fil enligt följande exempel:
“FullName”,”UserName”,”AppPool”,”VirtualDirectory”,”Binding”,”AuthType”,”AppPoolPassword”,”HostHeader”
“C:\Site1″,”DOMAIN\AppPoolUser”,”Site1″,”IIS:\Sites\Site1″,”@{protocol=”http”;bindingInformation=”*:80:hostheader.domain.suffix”},”User”,”Password” “E:\Site2″,”DOMAIN\AppPoolUser2″,”Site2″,”IIS:\Sites\Site2″,”@{protocol=”http”;bindingInformation=”*:80:”},”Identity” “E:\Logdirectory”,”DOMAIN\AppPoolUser2″ “”,””,””,”IIS:\Sites\Site2″,””,””,””,”another.hostheader.com”
För att skriptet ska fungera behöver du scriptet SetLocalPrivilege från Kyle Neier
Ändra rad 101 från:
[ValidateSet(“SeManageVolumePrivilege”, “SeLockMemoryPrivilege”)
till:
[ValidateSet(“SeManageVolumePrivilege”, “SeLockMemoryPrivilege”,”SeServiceLogonRight”)]
Tack Oscar Virot för lite hjälp med variabelhanteringen.
Automatiskt maila användare vars certifikat håller på att gå ut.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Script that mails users whos certificate is about to expire. # Created by: Lars Gustavsson # Version: 1.0 # Changelog: 1.0 Created # # Instructions: # Change the varibles for days when the certificate expires, the certificate server to use and the certificate template to filter by. # Make sure to set the execution policy to unrestricted with "set-execution policy unrestricted" #Importes the PSPKI Module, it needs to be installed first, download from http://pspki.codeplex.com/releases/view/110129 import-module PSPKI $Template = "SmartCard" $CAServer = "caserver.domain.suffix" #Days which to search for expired certificates in. $Days = "14" $MailFrom = "IT-Servicedesk@domain.suffix" $SMTP = "smtp.domain.suffix" $Subject = '"Your smartcard certificate is about to expire"' $UserRcpts = Get-CertificationAuthority $CAServer | Get-IssuedRequest -Property CertificateTemplate,UPN -Filter "NotAfter -ge $(Get-Date)", "NotAfter -le $((Get-Date).AddDays($Days))","CertificateTemplate -eq $Template" ForEach ($User in $UserRcpts) { $MailRcpt = $User.UPN $date = $MailRcpt.NotAfter $MailBody = '"Your smartcard expires ' + $date + ', please contact IT-Servicedesk to renew! You need your smartcard to your computer."' #Looks up the users email in Active Directory. $Mail = Get-ADUser -filter {(UserPrincipalName -eq $MailRcpt)} -Properties Mail #Checking that a mail was found before sending. if ($Mail.Mail -ne $Null) { Write-host "Send-MailMessage -To" $Mail.Mail "-Body $MailBody -From $MailFrom -Subject $Subject -SmtpServer $SMTP" } } |
Skriptet bygger på att du har modulen PSPKI installerad från http://pspki.codeplex.com/releases/view/110129
Veckans tanke om IT – Korkade setuper
Så, jag hade tänkt uppgradera DPM 2012 till SP1 också händer det som inte ska hända kl 20 på kvällen, stora röda kryss överallt, och enda vägen tillbaka är att gå tillbaka till senaste backup. Kul, absolut, eller inte…
Men hade det behövt hända?
Jag har lite synpunkter på hur den här setupen är skriven. Jag ska beskriva förfarandet.
Uppgraderingarna till System Center sviten är inga uppgraderingar i ordets rätta bemärkelse, en uppgradering tycker jag innebär att man låter allting vara och sedan bara lägger till det som har lagts till mellan versionerna. Den här uppgraderingen innebär att man installerar om hela produkten men behåller inställningarna.
Stegen i uppgraderingen är att man:
1. Gör backup av databasen, givetvis måste du göra detta själv!
2. Kör setupen och matar in all information, vilken databas man ska använda (befintlig) vilkan konton som ska användas, för detta kan givetvis inte setupen utläsa ur befintlig installation.
3. Setupen installerar om produkten.
4. Setupen uppgraderar databasen.
Givetvis gick allting snett i sista steget. Felet var: setup cannot grant the SERVERNAMN\DPMDBReaders$SERVERNAMN account access to the DPM database.
Verify that SQL Server is properly installed and that it is running.
ID: 832
Givetvis var SQL servern igång, och jag hade full access till den.
I god ro tänkte jag att, jaja, det är väl bara att ge kontot access till databasen så är det bara att köra sedan, men nej…
Sedan blev jag en smula irriterad, varför validerar inte setupen åtkomsten till databasen innan uppgraderingen, vem designade det här skräpet? Jag försöker köra setupen igen, valet jag har är att avinstallera och ta bort all information, och avinstallera och behålla informationen. Så jag är alltså fast med en SP1 installation och en databas som inte matchar.
Jag avinstallerar, och går sedan igenom setuploggen. Nu börjar det rktigt roliga.
Det första felet jag hittar är:
[2013-09-23 09:13:39] * Exception : Ignoring the following exception intentionally => System.Data.SqlClient.SqlException: Cannot drop the user ‘SERVERNAMN\DPMDBReaders$SERVERNAMN’, because it does not exist or you do not have permission.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
Först och främst har jag rättigheter att göra allt, ALLT! Men men ok, lugn, det står ju att den ignorerar felet, så hur stort problem kan det vara?
Nästa fel jag hittar är:
System.Data.SqlClient.SqlException: There is already an object named ‘DPMDBReaders$SERVERNAMN’ in the database.
CREATE SCHEMA failed due to previous errors.
Så, först påstår setupen att den inte kan ta bort ett objekt för det finns inte eller jag har inte åtkomst, sedan att den inte kan lägga till samma objekt för det redan finns???
Tack för kaffet, jag går och lägger mig…
Nåja lösningen var ju enkel, ta bort schemat i SQL databsen före man kör setupen så går allting bra. Jag vill bara påstå att en bra skriven setup förmodligen hade validerat de här sakerna INNAN den uppgraderade binärerna så jag hade sluppit göra en återställning till backup innan jag kunde lösa problemet och köra setupen igen. Mycket oflexibelt, inte IT-yogiskt alls. Skärpning MS!
Veckans tanke om IT – Namnstandarder
Så, du sitter och ska skapa upp en ny miljö, eller tänker städa upp din gamla. Du tänker, den här gången ska jag komma på en riktigt smart namnstandard så jag kan hålla reda på alla system.
Du börjar bygga, få se nu, jag lägger in ett S om det är en server, ett SE om den är i Sverige, ett V om den är virtualiserad, och sedan lägger jag till en förkortning för vilken roll som är installerad på den. Så en virtualiserad SQL server från sthlm i Sverige får namnet S-SE-STH-V-SQL-0001. Perfekt, nu kan jag läsa ut allt jag behöver ur namnet!
Men vänta nu, vad händer om du byter eller lägger till en roll på servern, om du byter ort. Virtuella maskiner idag kan ju flytta på sig hur som helst mellan datacenter. Dessutom det är med att sätta datornamn på varje server enligt den här standarden komme innebära att man förmodligen behöver ha en diskussion om varje ny server som ska skapas. Namnstandarden ska dokumenteras, läras ut till konsulter och nyanställda. Missförstånd kommer ske och servrar kommer heta fel saker, och förr eller senare är du tillbaka i oordning igen.
Mitt förslag är, skapa den enklaste formen av namnstandard du kan tänka dig, och sedan lite enklare ändå. Vad sägs om löpnummer, bara! Just det, bara löpnummer!
Men nä så kan man ju inte göra??? Hur ska man då veta vad servern gör eller står. Det finns ett fantastiskt bra sätt att lägga in det. På varje objekt i Active Directory finns flera andra fält. På en dator finns bland annat fälten (eller attributen om man ska vara korrekt) Description och Location. Vad sägs om att använda dom. Det fina med att använde de här attributen är att man kan ändra dom, precis när som helst, utan omstarter, och du kan använda många tecken och faktiskt skriva ut exakt vad det är för server.
Se namnet på en server som ett ID, ungefär som ditt personnr, ytterligare information kopplar man till ID:t. Är sedan servern något som användarna behöver komma åt genom att skriva namnet på server; skapa ett fint DNS Alias vettja!