Thursday, December 16, 2021

Troubleshooting DSC a bit

 Get-DscConfigurationStatus -OutVariable s


what resources are applied ok:

$s | select -ExpandProperty ResourcesInDesiredState | ogv


History of all DSC configuration that were applied:

Get-DscConfigurationStatus -All

above info is stored in C:\Windows\System32\Configuration\DSCStatusHistory.mof



view specific jobs:


gc 'C:\Windows\System32\Configuration\ConfigurationStatus\{E05CD7E7-5E6D-11EC-8F8E-000D3A4BD309}-0.details.json' -Encoding Unicode


Monday, November 29, 2021

 Create a new repo from github


git init

git remote add origin https://github.com/

git pull origin main


echo "# repo2" >> README.md

git add README.md

git commit -m "first commit"

git push -u origin main



Creating a default main brach:
git config --global init.defaultBranch main


Friday, October 29, 2021

Installing Docker on Windows

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

Install-Package -Name docker -ProviderName DockerMsftProvider -Force -RequiredVersion 19.03

Start-Service docker

docker image pull mcr.microsoft.com/windows/nanoserver:1809

docker container run -d -p 8080:80 sixeyed/whoami-dotnet:3.0

iwr -useb http://localhost:8080


Dowloading your image from Azure ACR


docker login acr.azurecr.io -u acr

docker image ls acr.azurecr.io

docker pull acr.azurecr.io/p056aapi:latest

  

Monday, October 4, 2021

Pushing new docker images to Azure ACR

1. Create a hello world program (Optional).

curl http://timelessname.com/elfbin/helloworld.tar.gz --output helloworld.tar.gz

mkdir helloworld

tar -xvf helloworld.tar.gz -C ./helloworld

cd helloworld/

./hello


2. Create a docker file

FROM scratch
COPY hello /
CMD ["/hello"]

3. Build docker:

docker build --tag hello .

4. Verify it can start:

docker run --rm hello

5. Login to ACR:

az login
az acr login --name <yourrepo>.azurecr.io

6. Rename your docker and push:

docker tag hello <yourrepo>.azurecr.io/samples/helloworld:v1
docker push <yourrepo>.azurecr.io/samples/helloworld:v1


6. Login interactively to container


a running container: docker exec -it <container-name-or-id> bash
run a container: docker run --entrypoint /bin/bash -it <image>

Thursday, September 30, 2021

Git - branches

 #Fast forwarding

#View all branches. * is current
git branch --list
#View remotes
git branch -r
#View all (local and remote)
git branch -a

#fetch remote branches
git fetch --all

#fetch single branche
git fetch origin "feature/name"

#Create a new branch pointing to where we are called branch1
git branch branch1

git branch --list
#Go to branch1
git checkout branch1

#use preferred command switch 
git switch branch1

#To create and checkout in one step:
git checkout -c branch1

#make some EDITS

#Move to main
git switch master
#we can look at the differences
git diff master..branch1
#If happy lets merge them. Remember we already switched to main. We are going to merge into this from branch1
git merge branch1
#Done. Notice was a fast-forward. Lets look at merged branches
git branch --merged

gitgraph

#We no longer need branch1. Remember use tags if you want some long lived reference
#This would only delete locally
#Remember to ALWAYS check it has been merged first before deleting
git branch --merged
git branch -d branch1


#Keeping the history

#go back 2 commits
git reset --hard HEAD~2

git branch branch1
git switch branch1

#This time specify NOT to perform a fast forward
git switch master
git diff master..branch1
git merge --no-ff branch1
git branch --merged

gitgraph
#Notice the merge was a new commit

#We can still delete branch1 as its still merged
git branch --merged
git branch -d branch1
#History is kept there was a branch
gitgraph


#3-way merge
#going back to first commit
git reset --hard HEAD^1
gitgraph

#Make the branch1 again with two commits
git branch branch1
git switch branch1
code jl.csv
git add .
git commit -m "Added Wonder Woman"
code jl.csv
git add .
git commit -m "Added The Flash"
gitgraph
git status

#Switch to main
git switch master
code jl.csv
git add .
git commit -m "Added Cyborg"

gitgraph
#More interesting. There is now NOT a direct path from branch1 to main
git status
#We will have conflicts given the changes we made
git merge branch1
#We need to fix them by editing the file it tells us and conflicts have been marked
code jl.csv
#We are in conflict status:
git status
git add .
git commit -m "Merged with branch1"

#Rebase - don't use it in public repos


#There is another option. Rebase
#Lets rewind before the merge by going back 1
git reset --hard HEAD~1
gitgraph

#WB19
#Need to be ON the branch we are performing the action on. We are rebasing branch1
git switch branch1
#check its clean
git status
#Lets rebase off main
git rebase master
#We will get conflicts as it replays each of the changes so each time will need to address and continue
code jl.csv
git add jl.csv
git rebase --continue

gitgraph
#Cleaner path. Copy next to the rebase whiteboard to compare!

#If now merge would just be a fast-forward since now a straight line from main and NOW 3-way merge
git status
git switch master
git merge branch1
#Cleanup
git branch --merged
git branch -d branch1
#Note if the remote master has changes you don't have and want to base on can git pull --rebase


Git - tagging

Lightweight tags: 

function gitgraph {git log --oneline --graph --decorate --all}

git tag v1.0.0
gitgraph
git tag v0.9.1 <previous commit>
gitgraph
git tag --list

you can look for this tag:
git show v1.0.0

Annotated tags: 

Those enable you to add messages and creating an object that references commit

git tag -a v0.0.1 <commit hash> -m "First version"

git show v0.0.1
#we see the TAG information AND then the commit it references
git cat-file -t v0.0.1
git cat-file -t v1.0.0

Git - moving between commits




 

Git - command to move files between stages






 

Tuesday, May 18, 2021

Installing AzurePolicyforWindows extension

 Short info for myself: how to install specific extension:


Set-AzVMExtension -ResourceGroupName yourGroup -ResourceName YourServerName `
-Publisher Microsoft.GuestConfiguration -Name AzurePolicyforWindows `
-ExtensionType ConfigurationforWindows -Location westeurope -TypeHandlerVersion 1.1

Set-AzVMExtension -ResourceGroupName yourGroup-ResourceName yourHost `
-Publisher Microsoft.Azure.NetworkWatcher -Type NetworkWatcherAgentWindows `
-TypeHandlerVersion 1.4 -Name "Microsoft.Azure.NetworkWatcher" `
-Location "Central US"

Saturday, May 15, 2021

How to update user properties with trusted domains

 Goal for this exercise is to setup a two domain contoso.local and foo.local and manage users in domain contoso using some user in domain foo.local.


First goal is to setup both domains with trust between them, there are plenty of solutions for this on internet.

Overall outcome is:

PS C:\Windows\system32> whoami
foo\vagrant
PS C:\Windows\system32> get-adtrust -Filter *


Direction               : BiDirectional
DisallowTransivity      : False
DistinguishedName       : CN=Contoso.local,CN=System,DC=foo,DC=local
ForestTransitive        : True
IntraForest             : False
IsTreeParent            : False
IsTreeRoot              : False
Name                    : Contoso.local
ObjectClass             : trustedDomain
ObjectGUID              : 4a044679-13b3-456b-8b8b-09a30d9b7252
SelectiveAuthentication : False
SIDFilteringForestAware : False
SIDFilteringQuarantined : False
Source                  : DC=foo,DC=local
Target                  : Contoso.local
TGTDelegation           : False
TrustAttributes         : 8
TrustedPolicy           :
TrustingPolicy          :
TrustType               : Uplevel
UplevelOnly             : False
UsesAESKeys             : False
UsesRC4Encryption       : False


I will use user foo\vagrant to update manager property of user contoso\user.

PS C:\Windows\system32> $u = Get-ADUser -Server dc1 -Filter * -Properties manager | ? name -eq "user"
PS C:\Windows\system32> $u


DistinguishedName : CN=user,OU=People,DC=Contoso,DC=local
Enabled           : True
GivenName         : user
Manager           :
Name              : user
ObjectClass       : user
ObjectGUID        : f6380a23-5d28-454f-9978-5455faf94a85
SamAccountName    : user
SID               : S-1-5-21-123626555-3626747555-2727358533-1109
Surname           :
UserPrincipalName : user@Contoso.local

Now another user manager:

PS C:\Windows\system32> $m = Get-ADUser -Server dc1 -Filter * -Properties manager | ? name -eq "manager"
PS C:\Windows\system32> $m


DistinguishedName : CN=Manager,OU=People,DC=Contoso,DC=local
Enabled           : True
GivenName         : Manager
Manager           :
Name              : Manager
ObjectClass       : user
ObjectGUID        : 0abf258d-22b0-4705-b66a-908e5ba2cf4a
SamAccountName    : manager
SID               : S-1-5-21-123626555-3626747555-2727358533-1107
Surname           :
UserPrincipalName : manager@Contoso.local

update manager property:

PS C:\Windows\system32> $uSet-ADUser -Manager $m
PS C:\Windows\system32> $u = Get-ADUser -Server dc1 -Filter * -Properties manager | ? name -eq "user"
PS C:\Windows\system32> $u


DistinguishedName : CN=user,OU=People,DC=Contoso,DC=local
Enabled           : True
GivenName         : user
Manager           : CN=Manager,OU=People,DC=Contoso,DC=local
Name              : user
ObjectClass       : user
ObjectGUID        : f6380a23-5d28-454f-9978-5455faf94a85
SamAccountName    : user
SID               : S-1-5-21-123626555-3626747555-2727358533-1109
Surname           :
UserPrincipalName : user@Contoso.local

PS C:\Windows\system32> whoami
foo\vagrant

Property Manager is updated.

Wednesday, May 12, 2021

How to load and execute DLL from Powershell.


Compile using Visual Studio Community following code:


Imports System

Public Module HelloWorld

Sub main()
Console.WriteLine("Hello World Using Visual Basic Code!")
'Msgbox("Hello World from My DotNET Assembly !")
    End Sub
End Module



Execution in Powershell:


$filename = "C:\Users\jarekole\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.dll"
$assembly = [Reflection.Assembly]::Loadfile($filename)

$assembly.gettype()

$assembly.fullName
$assembly.gettypes()
$assembly.GetName() |select * | fl
$assembly.GetTypes() | select UnderlyingSystemType 
[ConsoleApp1.HelloWorld]::main()


Thursday, May 6, 2021

 Configuring certificate autoenrollment:

New-Item -path HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\ -name AutoEnrollment

New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\AutoEnrollment\ -Name AEPolicy -Value 7

New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\AutoEnrollment\ -Name OfflineExpirationPercent -Value 10

New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\AutoEnrollment\ -Name OfflineExpirationStoreNames -Value MY


Binding certificate to web size that already has a binding:

Adjust your cert thumbprint


Import-Module WebAdministration

#check validity

Get-Item Cert:\LocalMachine\My\7FCF3A69C4E62637677953CB61F27D669154C6B5 | fl

#set bindings

dir cert:\localmachine\my\7FCF3A69C4E62637677953CB61F27D669154C6B5 | Set-Item IIS:\SslBindings\0.0.0.0!443