Windows Powershell

/Windows Powershell
Windows Powershell 2017-11-09T09:16:14+00:00

Konfigurer Windows Server Cores

# Start en powershell session på en remote server
Enter-PSSession -ComputerName MATHIAS-CORE

# Se alle tilgængelige features
Get-WindowsFeature

# Installer en web server (iis) role and management service
Install-WindowsFeature -Name Web-Server, Web-Mgmt-Service

# Vis installerede features
Get-WindowsFeature | Where-Object Installed -eq True

# Konfigurer remote management for IIS
Set-ItemProperty -Path “HKLM:\Software\Microsoft\WebManagement\Server” -Name “EnableRemoteManagement” -Value 1

# Konfigurer remote managent service til at starte automatisk
Set-Service WMSVC -StartupType Automatic

# Omdøb en computer
Rename-Computer -NewName MATHIAS-CORE -DomainCredential “MATDomain\administrator” -Force -Restart

# Afslut en remote powershell session
Exit-PSSession

# send en kommando over til en remote maskine (powershell remoting – http)
Invoke-Command -ComputerName MATHIAS-CORE -ScriptBlock { Get-Service W3SVC, WMSVC }

# Brug det indbyggede computernavn parameter (windows – dcom)
Get-Service -ComputerName MATHIAS-CORE

*Alle kommandoer skal køres i powershell.

Implementer Powershell Desired State Konfiguration

# Opret en DSC konfiguration til at installere IIS og supportere remote management
Configuration IISConfig {

# definer input parameter
param([string[]]$ComputerName = ‘localhost’
)

# target maskine(r) baseret på input parameter
node $ComputerName {

# installer IIS server rollen
WindowsFeature IIS {
Ensure = “Present”
Name = “Web-Server”
}

# installer IIS remote management service
WindowsFeature IISManagement {
Name = ‘Web-Mgmt-Service’
Ensure = ‘Present’
DependsOn = @(‘[WindowsFeature]IIS’)
}

# enable IIS remote management
Registry RemoteManagement {
Key = ‘HKLM:\SOFTWARE\Microsoft\WebManagement\Server’
ValueName = ‘EnableRemoteManagement’
ValueType = ‘Dword’
ValueData = ‘1’
DependsOn = @(‘[WindowsFeature]IIS’,'[WindowsFeature]IISManagement’)
}

# konfigurer remote management service
Service WMSVC {
Name = ‘WMSVC’
StartupType = ‘Automatic’
State = ‘Running’
DependsOn = ‘[Registry]RemoteManagement’
}

}

}

# Opret konfigurationen (.mof)
IISConfig -ComputerName WEB-NUG -OutputPath c:\nuggetlab

# push konfigurationen til MATHIAS-CORE
Start-DscConfiguration -Path c:\MATDomain -Wait -Verbose

# Start en powershell remote session
Enter-PSSession -ComputerName MATHIAS-CORE

# Vis installerede features
Get-WindowsFeature | Where-Object Installed -eq True

# Vis LCM egenskaber
Get-DscLocalConfigurationManager

# Vis Konfiguration status
Get-DscConfigurationStatus

# test konfigurations drift
Test-DscConfiguration

# afslut powershell remote session
Exit-PSSession

*Alle kommandoer køres i powershell

Opgrader og migrer til Windows Server 2016

# Vis server migration tools feature
Get-WindowsFeature -Name migration

# installer windows server migration tools
Install-WindowsFeature -Name migration

# naviger til smt directory
cd \windows\system32\servermigrationtools

# generer package til source maskine
.\smigdeploy.exe /package /architecture amd64 /os WS12R2 /path C:\MinMappe

# Kopirer package over til source maskine
Copy-Item -Path c:\MinMappe\SMT_ws12R2_amd64 -Destination \\srv2012-mat\c$\MATDomain-Recurse

# impoter smig cmdlets ind i sessionen
Add-PSSnapin Microsoft.Windows.ServerManager.Migration

# installer DHCP role og impoter settings!
Import-SmigServerSetting -FeatureID DHCP -Path c:\MinMappe\migration -Verbose -Force

*Alle kommandoer køres i powershell

Installer Windows Nano Server

# import nano server ps bits into session
Import-Module D:\NanoServer\NanoServerImageGenerator -Verbose

## MATHIAS-CORE01 ##
# opret en standard nano server vhdx
New-NanoServerImage -MediaPath D: -BasePath .\Base -TargetPath .\MATHIAS-CORE01.vhdx -DeploymentType Guest -Edition Datacenter -ComputerName MATHIAS-CORE01 -AdministratorPassword (ConvertTo-SecureString -String ‘Pa$$w0rd’ -AsPlainText -Force)

# opret og start vm
New-VM -Name MATHIAS-CORE01 -VHDPath .\MATHIAS-CORE01.vhdx -MemoryStartupBytes 1GB -Generation 2 | Start-VM

# Start en remote session med powershell direct
Enter-PSSession -VMName MATHIAS-CORE01

# vis processes, services, event logs
Get-Process
Get-Service
Get-WinEvent

# Afslut session
Exit-PSSession

##MATHIAS-CORE02 ##

# opret en nano server web server
New-NanoServerImage -MediaPath D: -BasePath .\Base -TargetPath .\MATHIAS-CORE02.vhdx -DeploymentType Guest -Edition Datacenter -ComputerName MATHIAS-CORE02 `
-InterfaceNameOrIndex Ethernet -Ipv4Address 192.168.1.115 -Ipv4SubnetMask 255.255.255.0 -Ipv4Gateway 192.168.1.1 -Ipv4Dns (“192.168.1.100″,”8.8.8.8”) `
-Package Microsoft-NanoServer-IIS-Package -AdministratorPassword (ConvertTo-SecureString -String ‘Pa$$w0rd’ -AsPlainText -Force)

# vis packages som er til rådighed
Get-NanoServerPackage -MediaPath D:

# create and start vm
New-VM -Name MATHIAS-CORE02 -VHDPath .\MATHIAS-CORE02.vhdx -MemoryStartupBytes 1GB -SwitchName vSwitch -Generation 2| Start-VM

# start en remote session med powershell direct
Enter-PSSession -VMName MATHIAS-CORE02

# vis iis service, logs, files
Get-Service W3SVC
Get-WinEvent -ListLog Microsoft-IIS*
Get-ChildItem -Path C:\inetpub

# vis installerede packages
Get-WindowsPackage -Online

# deaktiver firewall
Set-NetFirewallProfile -Name Public,Private,Domain -Enabled False

# afslut remote session
Exit-PSSession

*Alle kommandoer køres i powershell

Run Commands

Open Documents Folder documents
Open Videos folder videos
Open Downloads Folder downloads
Open Favorites Folder favorites
Open Recent Folder recent
Open Pictures Folder pictures
Adding a new Device devicepairingwizard
About Windows dialog winver
Add Hardware Wizard hdwwiz
Advanced User Accounts netplwiz
Advanced User Accounts azman.msc
Backup and Restore sdclt
Bluetooth File Transfer fsquirt
Calculator calc
Certificates certmgr.msc
Change Computer Performance Settings systempropertiesperformance
Change Data Execution Prevention Settings systempropertiesdataexecutionprevention
Change Data Execution Prevention Settings printui
Character Map charmap
ClearType Tuner cttune
Color Management colorcpl
Command Prompt cmd
Component Services comexp.msc
Component Services dcomcnfg
Computer Management compmgmt.msc
Computer Management compmgmtlauncher
Connect to a Projector displayswitch
Control Panel control
Create A Shared Folder Wizard shrpubw
Create a System Repair Disc recdisc
Data Execution Prevention systempropertiesdataexecutionprevention
Date and Time timedate.cpl
Default Location locationnotifications
Device Manager devmgmt.msc
Device Manager hdwwiz.cpl
Device Pairing Wizard devicepairingwizard
Diagnostics Troubleshooting Wizard msdt
Digitizer Calibration Tool tabcal
DirectX Diagnostic Tool dxdiag
Disk Cleanup cleanmgr
Disk Defragmenter dfrgui
Disk Management diskmgmt.msc
Display dpiscaling
Display Color Calibration dccw
Display Switch displayswitch
DPAPI Key Migration Wizard dpapimig
Driver Verifier Manager verifier
Ease of Access Center utilman
EFS Wizard rekeywiz
Event Viewer eventvwr.msc
Fax Cover Page Editor fxscover
File Signature Verification sigverif
Font Viewer fontview
Game Controllers joy.cpl
IExpress Wizard iexpress
Internet Explorer iexplore
Internet Options inetcpl.cpl
iSCSI Initiator Configuration Tool iscsicpl
Language Pack Installer lpksetup
Local Group Policy Editor gpedit.msc
Local Security Policy secpol.msc
Local Users and Groups lusrmgr.msc
Location Activity locationnotifications
Magnifier magnify
Malicious Software Removal Tool mrt
Manage Your File Encryption Certificates rekeywiz
Microsoft Management Console mmc
Microsoft Support Diagnostic Tool msdt
Mouse main.cpl
NAP Client Configuration napclcfg.msc
Narrator narrator
Network Connections ncpa.cpl
New Scan Wizard wiaacmgr
Notepad notepad
ODBC Data Source Administrator odbcad32
ODBC Driver Configuration odbcconf
On-Screen Keyboard osk
Paint mspaint
Pen and Touch tabletpc.cpl
People Near Me collab.cpl
Performance Monitor perfmon.msc
Performance Options systempropertiesperformance
Phone and Modem telephon.cpl
Phone Dialer dialer
Power Options powercfg.cpl
Presentation Settings presentationsettings
Print Management printmanagement.msc
Printer Migration printbrmui
Printer User Interface printui
Private Character Editor eudcedit
Problem Steps Recorder psr
Programs and Features appwiz.cpl
Protected Content Migration dpapimig
Region and Language intl.cpl
Registry Editor regedit
Registry Editor 32 regedt32
Remote Access Phonebook rasphone
Remote Desktop Connection mstsc
Resource Monitor resmon
Resultant Set of Policy rsop.msc
SAM Lock Tool syskey
Screen Resolution desk.cpl
Securing the Windows Account Database syskey
Services services.msc
Set Program Access and Computer Defaults computerdefaults
Share Creation Wizard shrpubw
Shared Folders fsmgmt.msc
Signout logoff
Snipping Tool snippingtool
Sound mmsys.cpl
Sound recorder soundrecorder
SQL Server Client Network Utility cliconfg
Sticky Notes stikynot
Stored User Names and Passwords credwiz
Sync Center mobsync
System Configuration msconfig
System Configuration Editor sysedit
System Information msinfo32
System Properties sysdm.cpl
System Properties (Advanced Tab) systempropertiesadvanced
System Properties (Computer Name Tab) systempropertiescomputername
System Properties (Hardware Tab) systempropertieshardware
System Properties (Remote Tab) systempropertiesremote
System Properties (System Protection Tab) systempropertiesprotection
System Restore rstrui
Task Manager taskmgr
Task Scheduler taskschd.msc
Trusted Platform Module (TPM) Management tpm.msc
Turn Windows features on or off optionalfeatures
User Account Control Settings useraccountcontrolsettings
Utility Manager utilman
Volume Mixer sndvol
Windows Action Center wscui.cpl
Windows Activation Client slui
Windows Anytime Upgrade Results windowsanytimeupgraderesults
Windows Disc Image Burning Tool isoburn
Windows Explorer explorer
Windows Fax and Scan wfs
Windows Firewall firewall.cpl
Windows Firewall with Advanced Security wf.msc
Windows Journal journal
Windows Media Player wmplayer
Windows Memory Diagnostic Scheduler mdsched
Windows Mobility Center mblctr
Windows Picture Acquisition Wizard wiaacmgr
Windows PowerShell powershell
Windows PowerShell ISE powershell_ise
Windows Remote Assistance msra
Windows Repair Disc recdisc
Windows Script Host wscript
Windows Update wuapp
Windows Update Standalone Installer wusa
Versione Windows winver
WMI Management wmimgmt.msc
WordPad write
XPS Viewer xpsrchvw
Check Disk

CMD

C:usersmhn>chkdsk /f /r C:

*Husk at kør CMD som Administrator

* Skift C: ud med hvad end drevbogstav du vil ha’ tjekket

*Denne kommando chekker din disk igennem for fejl i filer og prøve på at reparere dem

Computer model mm.

CMD

C:usersmhn> wmic computersystem get model,name,manufacturer,systemtype

*Denne kommando giver dig producent, modelnavn, hostnavn, og 32 eller 64 bit type.

Map netværks drev

CMD

C:usersmhn> Net use X: \192.168.25.2Faelles_Drev Kmmdat@2014! /USER:Mathias

*Denne kommando happer et netværks drev med bogstavet X, som peger på 192.168.25.2 i mappen fælles_drev med koden: Kmmdat@2014! og brugeren: Mathias.

For at slette et netværks drev (mapning) køres kommandoen

Net use X: /delete

eller

Net use * /delete (for at slette mapningen til alle netværks drev)

Find netværks drev brugere & password

CMD

C:usersmhn> wmic netuse where LocalName=”Z:” get UserName /value

*Denne kommando giver dig navnet / credentials på den bruger som har mappet netværks drevet

eksempel.

UserName=MitdomæneAdministrator

Oplysninger om netværksdrev i Regedit

Regedit

HKEY_CURRENT_USERNetwork

*Her kan du se de individuelle oplysninger om hvert netværksdrev

Connection Type, Provider Name, Provider Type, Remote Path, Username osv.

Hvis Username Står til 0x00000000(0), så betyder det at det er den aktive bruger som man er på der har mappet drevet.

Windows 10 oprydning

C:UsersMHN>Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

*Dette script ryder op i din windows.old folder samt unødvendige update filer, når den er færdig stå der “Sucessfully”.

eksempel

[==========================100.0%==========================]

The operation completed successfully.

Se Windows aktiverings status

C:UsersMHN>slmgr /xpr

*Denne kommando åbner en dialog boks hvor status på dit Windows vil fremgå.

Læs txt filer i CMD

C:UsersMHN>more TestTekstfil.txt

*Denne kommando åbner læser en fil i CMD.