POWERSHELL PowerShell script

AI-powered detection and analysis of PowerShell script files.

📂 Code
🏷️ .ps1
🎯 text/x-powershell
🔍

Instant POWERSHELL File Detection

Use our advanced AI-powered tool to instantly detect and analyze PowerShell script files with precision and speed.

File Information

File Description

PowerShell script

Category

Code

Extensions

.ps1

MIME Type

text/x-powershell

PowerShell Script

What is a PowerShell script file?

A PowerShell script (.ps1) file is a text file containing PowerShell commands, cmdlets, functions, and scripts that can be executed by the PowerShell runtime environment. PowerShell is both a command-line shell and a scripting language built on the .NET framework, designed for system administration, automation, and configuration management. PowerShell scripts provide object-oriented programming capabilities and deep integration with Windows systems and .NET technologies.

More Information

PowerShell was developed by Jeffrey Snover at Microsoft and first released in 2006 as "Monad," later renamed to PowerShell 1.0. The language was created to address limitations in traditional command-line interfaces by providing a more powerful, object-oriented approach to system administration and automation. Unlike traditional shells that work with text, PowerShell works with .NET objects, enabling rich data manipulation and system interaction.

PowerShell has evolved significantly since its initial release. PowerShell Core (6.0+) was rebuilt on .NET Core, making it cross-platform and open-source, running on Windows, Linux, and macOS. PowerShell 7+ unified Windows PowerShell and PowerShell Core, providing a single version that works across all platforms while maintaining backward compatibility with Windows PowerShell modules and scripts.

PowerShell Format

PowerShell has a distinctive syntax based on verb-noun cmdlets and object manipulation:

Basic Syntax

  • Cmdlets - Verb-Noun format (Get-Process, Set-Location)
  • Parameters - Named parameters with values (-Name "value")
  • Pipeline - Object passing between cmdlets with |
  • Variables - Start with $ symbol ($variable)
  • Comments - Single line # and multi-line <# #>
  • String interpolation - "Hello $name" or "Process: $($process.Name)"

Key Features

  • Object-oriented - Works with .NET objects, not just text
  • Rich cmdlets - Hundreds of built-in commands
  • Pipeline processing - Pass objects between commands
  • Remote management - Execute commands on remote systems
  • Integrated Scripting Environment - PowerShell ISE and VS Code
  • Extensive help system - Get-Help for any cmdlet

Data Types and Variables

  • .NET types - String, Int32, DateTime, Array, Hashtable
  • Automatic type conversion - Flexible type handling
  • Arrays - @(item1, item2, item3)
  • Hash tables - @{key1="value1"; key2="value2"}
  • Custom objects - [PSCustomObject]@{Property="Value"}
  • Strongly typed variables - [string]$name = "John"

Example PowerShell Script

<#
.SYNOPSIS
    System Information and Health Check Script
.DESCRIPTION
    Comprehensive system monitoring script that collects system information,
    performs health checks, and generates reports.
.PARAMETER ComputerName
    Name of the computer to check (default: localhost)
.PARAMETER ExportPath
    Path to export the report (default: current directory)
.EXAMPLE
    .\SystemHealthCheck.ps1 -ComputerName "SERVER01" -ExportPath "C:\Reports"
#>

[CmdletBinding()]
param(
    [Parameter(ValueFromPipeline = $true)]
    [string[]]$ComputerName = $env:COMPUTERNAME,
    
    [ValidateScript({Test-Path $_ -PathType Container})]
    [string]$ExportPath = (Get-Location).Path,
    
    [switch]$IncludeServices,
    [switch]$IncludeProcesses
)

# Script configuration
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

# Custom classes for structured data
class SystemInfo {
    [string]$ComputerName
    [string]$OperatingSystem
    [string]$Version
    [string]$Architecture
    [datetime]$LastBootTime
    [double]$UptimeDays
}

class DiskInfo {
    [string]$Drive
    [string]$Label
    [double]$SizeGB
    [double]$FreeSpaceGB
    [double]$UsedPercentage
    [string]$Status
}

# Function to get system information
function Get-SystemInformation {
    param([string]$Computer)
    
    try {
        Write-Verbose "Collecting system information for $Computer"
        
        $os = Get-CimInstance -ComputerName $Computer -ClassName Win32_OperatingSystem
        $cs = Get-CimInstance -ComputerName $Computer -ClassName Win32_ComputerSystem
        
        $lastBoot = $os.LastBootUpTime
        $uptime = (Get-Date) - $lastBoot
        
        return [SystemInfo]@{
            ComputerName = $Computer
            OperatingSystem = $os.Caption
            Version = $os.Version
            Architecture = $os.OSArchitecture
            LastBootTime = $lastBoot
            UptimeDays = [math]::Round($uptime.TotalDays, 2)
        }
    }
    catch {
        Write-Error "Failed to get system information for $Computer : $($_.Exception.Message)"
        return $null
    }
}

# Function to get disk information
function Get-DiskInformation {
    param([string]$Computer)
    
    try {
        Write-Verbose "Collecting disk information for $Computer"
        
        $disks = Get-CimInstance -ComputerName $Computer -ClassName Win32_LogicalDisk | 
                 Where-Object { $_.DriveType -eq 3 }  # Fixed drives only
        
        $diskInfo = foreach ($disk in $disks) {
            $sizeGB = [math]::Round($disk.Size / 1GB, 2)
            $freeSpaceGB = [math]::Round($disk.FreeSpace / 1GB, 2)
            $usedPercentage = [math]::Round((($sizeGB - $freeSpaceGB) / $sizeGB) * 100, 2)
            
            [DiskInfo]@{
                Drive = $disk.DeviceID
                Label = $disk.VolumeName
                SizeGB = $sizeGB
                FreeSpaceGB = $freeSpaceGB
                UsedPercentage = $usedPercentage
                Status = if ($usedPercentage -gt 90) { "Critical" } 
                        elseif ($usedPercentage -gt 80) { "Warning" } 
                        else { "OK" }
            }
        }
        
        return $diskInfo
    }
    catch {
        Write-Error "Failed to get disk information for $Computer : $($_.Exception.Message)"
        return @()
    }
}

# Function to get service information
function Get-ServiceStatus {
    param([string]$Computer)
    
    if (-not $IncludeServices) { return @() }
    
    try {
        Write-Verbose "Collecting service information for $Computer"
        
        $criticalServices = @(
            "Spooler", "BITS", "Themes", "AudioSrv", "Dhcp", 
            "DNS", "EventLog", "PlugPlay", "RpcSs", "Schedule"
        )
        
        $services = Get-Service -ComputerName $Computer -Name $criticalServices -ErrorAction SilentlyContinue |
                   Select-Object Name, Status, StartType, DisplayName
        
        return $services
    }
    catch {
        Write-Warning "Failed to get service information for $Computer : $($_.Exception.Message)"
        return @()
    }
}

# Function to generate HTML report
function New-HTMLReport {
    param(
        [SystemInfo]$SystemInfo,
        [DiskInfo[]]$DiskInfo,
        [array]$ServiceInfo,
        [string]$OutputPath
    )
    
    $reportDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $fileName = "SystemReport_$($SystemInfo.ComputerName)_$(Get-Date -Format 'yyyyMMdd_HHmmss').html"
    $fullPath = Join-Path $OutputPath $fileName
    
    $html = @"
<!DOCTYPE html>
<html>
<head>
    <title>System Report - $($SystemInfo.ComputerName)</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .header { background-color: #2E8B57; color: white; padding: 15px; border-radius: 5px; }
        .section { margin: 20px 0; }
        table { border-collapse: collapse; width: 100%; margin: 10px 0; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
        .status-ok { background-color: #d4edda; }
        .status-warning { background-color: #fff3cd; }
        .status-critical { background-color: #f8d7da; }
    </style>
</head>
<body>
    <div class="header">
        <h1>System Health Report</h1>
        <p>Computer: $($SystemInfo.ComputerName) | Generated: $reportDate</p>
    </div>
    
    <div class="section">
        <h2>System Information</h2>
        <table>
            <tr><th>Property</th><th>Value</th></tr>
            <tr><td>Operating System</td><td>$($SystemInfo.OperatingSystem)</td></tr>
            <tr><td>Version</td><td>$($SystemInfo.Version)</td></tr>
            <tr><td>Architecture</td><td>$($SystemInfo.Architecture)</td></tr>
            <tr><td>Last Boot Time</td><td>$($SystemInfo.LastBootTime)</td></tr>
            <tr><td>Uptime (Days)</td><td>$($SystemInfo.UptimeDays)</td></tr>
        </table>
    </div>
    
    <div class="section">
        <h2>Disk Information</h2>
        <table>
            <tr><th>Drive</th><th>Label</th><th>Size (GB)</th><th>Free Space (GB)</th><th>Used %</th><th>Status</th></tr>
"@
    
    foreach ($disk in $DiskInfo) {
        $statusClass = switch ($disk.Status) {
            "OK" { "status-ok" }
            "Warning" { "status-warning" }
            "Critical" { "status-critical" }
        }
        $html += "<tr class='$statusClass'><td>$($disk.Drive)</td><td>$($disk.Label)</td><td>$($disk.SizeGB)</td><td>$($disk.FreeSpaceGB)</td><td>$($disk.UsedPercentage)%</td><td>$($disk.Status)</td></tr>"
    }
    
    $html += @"
        </table>
    </div>
</body>
</html>
"@
    
    $html | Out-File -FilePath $fullPath -Encoding UTF8
    return $fullPath
}

# Main execution block
try {
    Write-Host "Starting System Health Check..." -ForegroundColor Green
    
    $allResults = foreach ($computer in $ComputerName) {
        Write-Host "Processing $computer..." -ForegroundColor Yellow
        
        # Test connectivity
        if (-not (Test-Connection -ComputerName $computer -Count 1 -Quiet)) {
            Write-Warning "Cannot reach $computer. Skipping..."
            continue
        }
        
        # Collect information
        $systemInfo = Get-SystemInformation -Computer $computer
        $diskInfo = Get-DiskInformation -Computer $computer
        $serviceInfo = Get-ServiceStatus -Computer $computer
        
        if ($systemInfo) {
            # Generate report
            $reportPath = New-HTMLReport -SystemInfo $systemInfo -DiskInfo $diskInfo -ServiceInfo $serviceInfo -OutputPath $ExportPath
            Write-Host "Report generated: $reportPath" -ForegroundColor Green
            
            [PSCustomObject]@{
                ComputerName = $computer
                SystemInfo = $systemInfo
                DiskInfo = $diskInfo
                ServiceInfo = $serviceInfo
                ReportPath = $reportPath
            }
        }
    }
    
    # Summary
    Write-Host "`nSummary:" -ForegroundColor Cyan
    Write-Host "Computers processed: $($allResults.Count)" -ForegroundColor White
    Write-Host "Reports generated in: $ExportPath" -ForegroundColor White
    
    return $allResults
}
catch {
    Write-Error "Script execution failed: $($_.Exception.Message)"
    exit 1
}

How to work with PowerShell script files

PowerShell provides comprehensive tools and environments for script development:

PowerShell Versions

  • Windows PowerShell 5.1 - Built into Windows, .NET Framework-based
  • PowerShell 7+ - Cross-platform, .NET Core/.NET 5+ based
  • PowerShell ISE - Integrated Scripting Environment (Windows only)
  • PowerShell Core 6.x - Earlier cross-platform version

Development Environments

  • Visual Studio Code - Excellent PowerShell extension with debugging
  • PowerShell ISE - Traditional Windows PowerShell IDE
  • Windows Terminal - Modern terminal with PowerShell support
  • Azure Cloud Shell - Browser-based PowerShell environment

Execution Policies

  • Restricted - No scripts allowed (default on some systems)
  • RemoteSigned - Local scripts run, remote scripts need signatures
  • AllSigned - All scripts must be digitally signed
  • Unrestricted - All scripts allowed (security risk)
  • Bypass - No restrictions, no warnings

Module Management

  • PowerShell Gallery - Central repository for PowerShell modules
  • Install-Module - Install modules from repositories
  • Import-Module - Load modules into current session
  • Get-Module - List available and loaded modules
  • ActiveDirectory - Active Directory management
  • AzureRM/Az - Azure cloud management
  • Exchange - Exchange Server management
  • Hyper-V - Hyper-V virtualization management
  • Pester - Testing framework for PowerShell
  • PSScriptAnalyzer - Static code analysis tool

Advanced PowerShell Features

PowerShell includes sophisticated programming capabilities:

  • Classes and enums - Object-oriented programming
  • Workflows - Long-running, resumable processes
  • Desired State Configuration - Infrastructure configuration management
  • Remoting - Execute commands on remote systems
  • Background jobs - Asynchronous command execution
  • Event handling - Respond to system and application events

Security and Best Practices

PowerShell security considerations:

  • Execution policies - Control script execution permissions
  • Code signing - Digital signatures for script authenticity
  • Constrained endpoints - Restricted PowerShell sessions
  • Just Enough Administration - Minimal privilege access
  • Logging and auditing - Track PowerShell activity
  • Input validation - Validate and sanitize user inputs

DevOps and Automation

PowerShell is essential for Windows DevOps:

  • Azure DevOps - Build and release pipelines
  • Configuration management - DSC and Ansible integration
  • Infrastructure as Code - ARM templates and Terraform
  • Container management - Docker and Kubernetes operations
  • CI/CD automation - Automated testing and deployment

Common Use Cases

PowerShell scripts are widely used for:

  • System administration - User management, system configuration
  • Active Directory management - Domain and user administration
  • Azure cloud management - Resource provisioning and management
  • Exchange administration - Email system management
  • Automation workflows - Business process automation
  • Reporting and monitoring - System health and performance reports
  • Software deployment - Application installation and updates
  • Data processing - ETL operations and data transformation
  • Security operations - Compliance checking and vulnerability assessment

AI-Powered POWERSHELL File Analysis

🔍

Instant Detection

Quickly identify PowerShell script files with high accuracy using Google's advanced Magika AI technology.

🛡️

Security Analysis

Analyze file structure and metadata to ensure the file is legitimate and safe to use.

📊

Detailed Information

Get comprehensive details about file type, MIME type, and other technical specifications.

🔒

Privacy First

All analysis happens in your browser - no files are uploaded to our servers.

Related File Types

Explore other file types in the Code category and discover more formats:

Start Analyzing POWERSHELL Files Now

Use our free AI-powered tool to detect and analyze PowerShell script files instantly with Google's Magika technology.

Try File Detection Tool