CoolFace
Apppublic

Nudel5uppe/powershellprodigy

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
powershell.html65 linesDownload Raw Back to root
1<!DOCTYPE html>2<html lang="en">3<head>4    <meta charset="UTF-8">5    <meta name="viewport" content="width=device-width, initial-scale=1.0">6    <title>PowerShell Scripting</title>7    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">8    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>9    <script>hljs.highlightAll();</script>10    <script src="https://cdn.tailwindcss.com"></script>11</head>12<body class="bg-gray-100">13    <div class="container mx-auto px-4 py-8">14        <h1 class="text-3xl font-bold text-blue-800 mb-6">PowerShell Script Examples</h1>15        16        <div class="bg-white rounded-lg shadow-md p-6 mb-8">17            <h2 class="text-xl font-semibold mb-4">Basic System Info</h2>18            <pre><code class="language-powershell">19# Get system information20$computerSystem = Get-CimInstance Win32_ComputerSystem21$os = Get-CimInstance Win32_OperatingSystem22$processor = Get-CimInstance Win32_Processor23 24Write-Host "System Information"25Write-Host "-----------------"26Write-Host "Manufacturer: $($computerSystem.Manufacturer)"27Write-Host "Model: $($computerSystem.Model)"28Write-Host "OS: $($os.Caption) $($os.Version)"29Write-Host "Processor: $($processor.Name)"30Write-Host "RAM: $([math]::round($computerSystem.TotalPhysicalMemory/1GB, 2)) GB"31            </code></pre>32        </div>33 34        <div class="bg-white rounded-lg shadow-md p-6 mb-8">35            <h2 class="text-xl font-semibold mb-4">File Operations</h2>36            <pre><code class="language-powershell">37# Find and delete old files38$days = 3039$targetFolder = "C:\Temp\OldFiles"40$cutoffDate = (Get-Date).AddDays(-$days)41 42Get-ChildItem -Path $targetFolder -Recurse -File | 43    Where-Object { $_.LastWriteTime -lt $cutoffDate } |44    Remove-Item -Force -WhatIf45            </code></pre>46        </div>47 48        <div class="bg-white rounded-lg shadow-md p-6">49            <h2 class="text-xl font-semibold mb-4">Active Directory Query</h2>50            <pre><code class="language-powershell">51# Get AD users who haven't logged in recently52Import-Module ActiveDirectory53 54$inactiveDays = 9055$searchBase = "OU=Users,DC=domain,DC=com"56 57Get-ADUser -Filter {Enabled -eq $true} -SearchBase $searchBase -Properties LastLogonDate |58    Where-Object { $_.LastLogonDate -lt (Get-Date).AddDays(-$inactiveDays) } |59    Select-Object Name, SamAccountName, LastLogonDate |60    Export-Csv -Path "InactiveUsers.csv" -NoTypeInformation61            </code></pre>62        </div>63    </div>64</body>65</html>