Client Settings

Get Windows Key

wmic path softwarelicensingservice get OA3xOriginalProductKey 

powershell „(Get-WmiObject –query ‚select * from SoftwareLicensingService‚).OA3xOriginalProductKey“ 

Who is logged in:

qwinsta /server:ws01

$computer = ‚ComputerXYZ‘  

gwmi win32_LogonSession -Computer $computer -Filter ‚LogonType=2 or LogonType=10‘ | %{  

    gwmi -ComputerName $computer -Query „Associators of {Win32_LogonSession.LogonId=$($_.LogonId)} Where AssocClass=Win32_LoggedOnUser Role=Dependent“ | select -Expand Name  

}

Speicherplatz auslesen:

Get-PSDrive | Where {$_.Free} 

Systeminfos von Machine:

Get-ComputerInfo | fl CsManufacturer,CsModel,CsName, ` CsPhyicallyInstalledMemory,CsProcessors,CsNumberOfProcessors, ` CsNumberOfLogicalProcessors,WindowsInstallDateFromRegistry, `

WindowsProductName,OsArchitecture 

Powershell Remote Session

Pre-Check:

Test-WsMan COMPUTER 

Enable-PSRemoting -Force 

Enter-PSSession -ComputerName COMPUTER -Credential USER 

$Computer = „KitchenComputer001“ $Credential = Get-Credential Enter-PSSession –ComputerName $Computer –Credential $Credential 

Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-UICulture}

Invoke-Command -ComputerName Server01, Server02 -FilePath c:\Scripts\DiskCollect.ps1

Invoke-Command –Session $RemoteSession –ScriptBlock { Get-Host } 

Invoke-Command -Computername <Name des Computers> {Get-PSDrive | Where {$_.Free}} 

Invoke-Command -ComputerName ws02 -ScriptBlock { \\Ws02\c$\IT_Admin\M365\oneDriveSetup.exe /allusers /qn }

Export Session

$S = New-PSSession -ComputerName Server01

Export-PSSession -Session $S -OutputModule Server01

Import Session:

$S = New-PSSession -ComputerName Server01

Import-PSSession -Session $S

Exit-PSSession 

$remoteSession = New-PSSession -ComputerName „WS03“

Enter-PSSession $remoteSession

Copy-Item „\\v-dcsrv01\Daten\Allgmein\Programme\M365“ -Destination „C:\IT-Admin\“ -ToSession $remoteSession

Exit-PSSessionEnable-PSRemoting –Force

Defrag SSD:

powershell -Executionpolicy Bypass -Command „Optimize-Volume -DriveLetter C -ReTrim -Verbose

Grösse der Benutzerprofile auslesen:

$ErrorActionPreference = „SilentlyContinue“

$UserFolders = Get-ChildItem -Path „C:\Users“ -Force -Directory

ForEach ( $Folder in $UserFolders ) {

[UInt64]$FolderSize = ( Get-Childitem -Path $Folder.FullName -Force -Recurse | Measure-Object -Property „Length“ -Sum).Sum    
    [PSCustomObject]@{
        FolderName    = $Folder.BaseName
        FolderPath    = $Folder.FullName
        Size          = $FolderSize
    }

Benutzerprofil umbenennen:

Windows Profil löschen aber Daten nur umbenennen, funktioniert nur wenn in der Registry der Benutzer gelöscht wird:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

Externer Zugriff mit Powershell:

Enter-PSSession -ComputerName v-dcsrv02 –credential user\passwort

Invoke-Command -ScriptBlock {Restart-Service spooler;Get-Date; wmic qfe list} -ComputerName wks11 

OneDrive

Installing for all Users of a machine:

OneDriveSetup.exe /allusers 

Aktuelle OneDrive GPO Templates auf PC suchenm (werden nicht mit Office Templates mitgeliefert):

$OnePath = („$env:LOCALAPPDATA\Microsoft\OneDrive“, ` 

„$env:ProgramFiles(x86)\Microsoft\OneDrive“, ` 

„$env:ProgramFiles\Microsoft OneDrive“) 

 

$OnePath | foreach{ 

    Get-ChildItem „$_\*\adm\onedrive.adm?“ -ErrorAction SilentlyContinue