├── .gitignore ├── screenshots └── cmdlet1.png ├── clean-system-local.ps1 ├── PSReadLine-Commands.txt ├── git-clone-continuous.ps1 ├── network-tools-install-modules.ps1 ├── git-clone-list.ps1 ├── remove-all-print-jobs.ps1 ├── get-cmdlets-list.ps1 ├── silent-chrome-install.ps1 ├── ping-server.ps1 ├── list-top-ten-processes.ps1 ├── setup-print-server.ps1 ├── get-module-commands.ps1 ├── IIS-restart-all-apppools.ps1 ├── docs └── index.html ├── git-pull.ps1 ├── AD-get-server-status.ps1 ├── git-init.ps1 ├── list-tables-mysql.ps1 ├── setup-file-server.ps1 ├── monitor-webpage.ps1 ├── download-web-files.ps1 ├── list-tables-sqlserver.ps1 ├── readme.md ├── iis-tools.ps1 ├── nodejs-forever-start-apps.ps1 ├── create-startup-executable.ps1 ├── create-startup-powershell-script.ps1 ├── list-gce.ps1 ├── file-search.ps1 ├── file-watcher.ps1 ├── create-cmdlets-js.ps1 ├── PowerShellHelp ├── PowershellHelp.ps1 ├── PowershellHelp.resx └── PowershellHelp.designer.ps1 ├── create-csv-from-mysql-table.ps1 ├── AD-passwords-expiring-csv.ps1 ├── AD-computers-html-report.ps1 ├── aws-cloudwatch-custom-metrics-config.ps1 ├── network-tools.ps1 ├── transfer-365-user.ps1 ├── IIS-delete-website.ps1 ├── create-csv-from-sqlserver-table.ps1 ├── ssh-stop-web.ps1 ├── ssh-apt-upgrade-ubuntu.ps1 ├── ssh-start-web.ps1 ├── ssh-restart-web.ps1 ├── hyperv-backup-vm.ps1 ├── ssh-new-db-mongodb.ps1 ├── AD-passwords-expiring-soon-email.ps1 ├── setup-domain-controller.ps1 ├── ssh-new-db-mysql.ps1 ├── Powershell-Cmdlet-Explorer ├── Powershell-Cmdlet-Explorer.ps1 └── Powershell-Cmdlet-Explorer.designer.ps1 ├── copy-everything.ps1 ├── wsus-critical-report.ps1 ├── AD-computers-network-html-report.ps1 ├── azure-upload-vhd.ps1 ├── send-email.ps1 ├── plex-manufacturing-cloud.ps1 ├── system-info-local-json.ps1 ├── aws-cloudwatch-custom-metrics.ps1 ├── test-server.ps1 ├── system-info-html-report-local.ps1 ├── flancy-sys-info-ws.ps1 ├── server-system-info-website.ps1 └── Report-Functions.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | debug.log 2 | .vs 3 | staging-scripts 4 | PowerShellHelp -------------------------------------------------------------------------------- /screenshots/cmdlet1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrussellfreelance/powershell-scripts/HEAD/screenshots/cmdlet1.png -------------------------------------------------------------------------------- /clean-system-local.ps1: -------------------------------------------------------------------------------- 1 | # This script is super simple, it calls a couple clean up utilties. 2 | # Call disk cleaner 3 | cleanmgr.exe /dC 4 | # Call disk defrag 5 | defrag.exe /C -------------------------------------------------------------------------------- /PSReadLine-Commands.txt: -------------------------------------------------------------------------------- 1 | PSConsoleHostReadLine 2 | Get-PSReadLineKeyHandler 3 | Get-PSReadLineOption 4 | Remove-PSReadLineKeyHandler 5 | Set-PSReadLineKeyHandler 6 | Set-PSReadLineOption 7 | -------------------------------------------------------------------------------- /git-clone-continuous.ps1: -------------------------------------------------------------------------------- 1 | # This script contiuously prompts for a git repo and downloads it 2 | while (1) { 3 | $repo = Read-Host "Please enter the git repo url" 4 | git clone $repo 5 | } -------------------------------------------------------------------------------- /network-tools-install-modules.ps1: -------------------------------------------------------------------------------- 1 | # These are the three modules required by the network-tools utility. 2 | Install-Module SimpleMenu 3 | Install-Module AssetInventory 4 | Install-Module PowerShellCookbook 5 | Install-Module HostUtilities -------------------------------------------------------------------------------- /git-clone-list.ps1: -------------------------------------------------------------------------------- 1 | # This script clones a list of repos from a text file 2 | # repos.txt should just be a list of .git URLs, separated by a carriage return 3 | $repos = Get-Content "$PSScriptRoot\repos.txt" 4 | foreach ($repo in $repos) { 5 | git clone $repo 6 | } -------------------------------------------------------------------------------- /remove-all-print-jobs.ps1: -------------------------------------------------------------------------------- 1 | # This script removes all jobs from all printers 2 | $printers = Get-Printer 3 | foreach ($printer in $printers) { 4 | $printjobs = Get-PrintJob -PrinterObject $printer 5 | foreach ($printjob in $printjobs) { 6 | Remove-PrintJob -InputObject $printjob 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /get-cmdlets-list.ps1: -------------------------------------------------------------------------------- 1 | # This is a SUPER simple script (one could barely call it that) that outputs the list of cmdlets on the current machine 2 | $commands = Get-Command 3 | # Loop through each command and add the name to a text file 4 | foreach ($command in $commands) { 5 | Add-Content "$PSScriptRoot\cmdlets.txt" $command.Name 6 | } -------------------------------------------------------------------------------- /silent-chrome-install.ps1: -------------------------------------------------------------------------------- 1 | ### Silently installs latest google chrome ### 2 | $Path = $env:TEMP; 3 | $Installer = "chrome_installer.exe" 4 | Invoke-WebRequest "http://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path\$Installer 5 | Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait 6 | Remove-Item $Path\$Installer -------------------------------------------------------------------------------- /ping-server.ps1: -------------------------------------------------------------------------------- 1 | # This script pings a server or IP every interval. This is useful for servers that "go to sleep" (for lack of a better term) when they aren't receiving any activity. 2 | param( 3 | [Parameter(Mandatory=$true)] 4 | $server, 5 | [Parameter(Mandatory=$true)] 6 | $intervalSeconds 7 | ) 8 | while (1) { 9 | ping $server 10 | Start-Sleep -Seconds $intervalSeconds 11 | } -------------------------------------------------------------------------------- /list-top-ten-processes.ps1: -------------------------------------------------------------------------------- 1 | # This is a super simple script that lists the top 10 running processes by memory consumption. 2 | # Get process list, sort by memory, and select top 10 3 | $top10proc = Get-Process | Sort-Object WorkingSet -Descending | Select-Object Name -First 10 4 | # List out top processes 5 | Write-Host "Top 10 Running Processes by Memory:" 6 | foreach ($proc in $top10proc) { 7 | Write-Host $proc.Name 8 | } -------------------------------------------------------------------------------- /setup-print-server.ps1: -------------------------------------------------------------------------------- 1 | # This script installs the necessary Windows features for setting up a print server. 2 | # Since this is a brand new server/virtual machine, we need to set the Powershell execution policy 3 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force 4 | # Install features 5 | Install-WindowsFeature Print-Services 6 | Install-WindowsFeature Print-Server 7 | Install-WindowsFeature Print-Scan-Server 8 | Install-WindowsFeature Print-LPD-Service -------------------------------------------------------------------------------- /get-module-commands.ps1: -------------------------------------------------------------------------------- 1 | # This script creates a text file with a list of commands for the module specified. It's nice for having a reference of commands for a certain module. 2 | # Grab the module name 3 | $module = Read-Host "Please enter the module name" 4 | # Retrieve commands just for that module 5 | $commands = Get-Command -Module $module 6 | # Loop through commands and add each to file 7 | foreach ($command in $commands) { 8 | Add-Content "$PSScriptRoot/$module-Commands.txt" $command.Name 9 | } 10 | -------------------------------------------------------------------------------- /IIS-restart-all-apppools.ps1: -------------------------------------------------------------------------------- 1 | # This script remotely restarts all the web app pools on the specified web server 2 | param( 3 | [Parameter(Mandatory=$true)]$webserver 4 | ) 5 | # Invoke command on remote web server 6 | Invoke-Command -ComputerName $webserver -ScriptBlock { 7 | Import-Module WebAdministration 8 | # Get list of app pools 9 | $apppools = Get-ChildItem IIS:\AppPools 10 | # Loop through list and restart each one 11 | foreach ($pool in $apppools) { 12 | Restart-WebAppPool -Name $pool.Name 13 | } 14 | } -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /git-pull.ps1: -------------------------------------------------------------------------------- 1 | # This script pulls updates from git for every folder in a directory. 2 | # This can be useful if you made changes to several apps and want to retrieve the updates for all apps by just running one script. 3 | # You can also schedule in in Task Scheduler to periodically grab updates 4 | param([Parameter(Mandatory=$true)]$rootFolder) 5 | $folders = Get-ChildItem $rootFolder 6 | foreach ($folder in $folders) { 7 | $foldername = $folder.Name 8 | # Set the current location as the current folder 9 | Set-Location "$rootFolder\$foldername" 10 | # Call git to pull updates 11 | git pull 12 | } -------------------------------------------------------------------------------- /AD-get-server-status.ps1: -------------------------------------------------------------------------------- 1 | # This script checks to see if a AD computer is live. It is nice for cleaning up old environments and cleaning up old AD entries. 2 | # NOTE: test-server.ps1 is included in this directory, and it is required for this script to work. 3 | . "$PSScriptRoot\test-server.ps1" 4 | $servers = Get-ADComputer -Filter * 5 | 6 | foreach($server in $servers) { 7 | Write-Host "Testing "$server.DNSHostName 8 | $results = Test-Server -ComputerName $server.DNSHostName 9 | if ($results.Ping) { 10 | Add-Content "$PSScriptRoot\connectedservers.txt" $server.DNSHostName 11 | } else { 12 | Add-Content "$PSScriptRoot\failedservers.txt" $server.DNSHostName 13 | } 14 | } -------------------------------------------------------------------------------- /git-init.ps1: -------------------------------------------------------------------------------- 1 | # This script initializes a git repository in the folder specified, adds the files, makes the first commit, adds the remote repository, and pushes the repository. 2 | # All you have to do is pass in the full path to the folder and the url of the repository 3 | param( 4 | [Parameter(Mandatory=$true)]$path, 5 | [Parameter(Mandatory=$true)]$url 6 | ) 7 | # Set the current working directory to the folder path 8 | Set-Location $path 9 | # Initialize an empty git repo 10 | git init 11 | # Add files 12 | git add . 13 | # Make your first commit 14 | git commit -am "First commit!" 15 | # Add remote origin 16 | git remote add origin $url 17 | # Push repository 18 | git push -u origin master -------------------------------------------------------------------------------- /list-tables-mysql.ps1: -------------------------------------------------------------------------------- 1 | # This script lists all of the tables in a MySQL database and exports the list as a CSV 2 | # Install-Module InvokeQuery 3 | # Run the above command if you do not have this module 4 | param( 5 | [Parameter(Mandatory=$true)]$server, 6 | [Parameter(Mandatory=$true)]$database, 7 | [Parameter(Mandatory=$true)]$dbuser, 8 | [Parameter(Mandatory=$true)]$dbpass 9 | ) 10 | $csvfilepath = "$PSScriptRoot\mysql_tables.csv" 11 | $result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql "SHOW TABLES" -CommandTimeout 10000 12 | $result | Export-Csv $csvfilepath -NoTypeInformation -------------------------------------------------------------------------------- /setup-file-server.ps1: -------------------------------------------------------------------------------- 1 | # This script installs the necessary Windows features for setting up a file server. 2 | # Since this is a brand new server/virtual machine, we need to set the Powershell execution policy 3 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force 4 | # Install features 5 | Install-WindowsFeature File-Services 6 | Install-WindowsFeature FS-FileServer 7 | Install-WindowsFeature FS-BranchCache 8 | Install-WindowsFeature FS-Data-Deduplication 9 | Install-WindowsFeature FS-DFS-Namespace 10 | Install-WindowsFeature FS-DFS-Replication 11 | Install-WindowsFeature FS-Resource-Manager 12 | Install-WindowsFeature FS-VSS-Agent 13 | Install-WindowsFeature FS-iSCSITarget-Server 14 | Install-WindowsFeature iSCSITarget-VSS-VDS 15 | Install-WindowsFeature FS-NFS-Service 16 | Install-WindowsFeature FS-SyncShareService -------------------------------------------------------------------------------- /monitor-webpage.ps1: -------------------------------------------------------------------------------- 1 | param([Parameter(Mandatory=$true)]$url) 2 | . $PSScriptRoot\send-email.ps1 3 | # This script checks every hour to see if a website returns a 200 status code. If it doesn't, the script sends an email. 4 | $interval = 3600 # You can change the interval, by default set as 1 hour 5 | while (1) { 6 | $request = Invoke-WebRequest -Uri $url 7 | if ($request.StatusCode -ne 200) { 8 | $subject = "Your Website is Down" 9 | $from = "downdetector@domain.com" # Replace this with the desired from address 10 | $to = @() # Specify the email recipient(s) 11 | $cc = @() 12 | $bcc = @() 13 | $body = "

$url is down.

" 14 | $priority = "High" 15 | $attachments = @() 16 | Send-Email($subject, $body, $from, $to, $cc, $bcc, $priority, $attachments) 17 | } 18 | Start-Sleep -Seconds $interval 19 | } -------------------------------------------------------------------------------- /download-web-files.ps1: -------------------------------------------------------------------------------- 1 | # This script allows you to download all the files listed on a website's directory listing. 2 | # First, you must copy the list of files from your web browser into a CSV named files.csv , and it must have a header row that says "name". Then put that csv in the same directory as the script. 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | $url 6 | ) 7 | # Import the CSV of file names 8 | $files = Import-Csv "$PSScriptRoot\files.csv" 9 | # Create a directory to store downloaded files in 10 | New-Item -ItemType Directory -Path "$PSScriptRoot\DownloadedFiles" 11 | # Loop through each file and download it 12 | foreach ($file in $files) { 13 | $filename = $file.name 14 | Write-Host "Downloading $filename..." 15 | $client = New-Object System.Net.WebClient 16 | $client.DownloadFile("$url/$filename", "$PSScriptRoot\DownloadedFiles\$filename") 17 | } -------------------------------------------------------------------------------- /list-tables-sqlserver.ps1: -------------------------------------------------------------------------------- 1 | # This script lists all of the tables in a SQL Server database and exports the list as a CSV 2 | # Install-Module InvokeQuery 3 | # Run the above command if you do not have this module 4 | param( 5 | [Parameter(Mandatory=$true)]$server, 6 | [Parameter(Mandatory=$true)]$database, 7 | [Parameter(Mandatory=$true)]$username, 8 | [Parameter(Mandatory=$true)]$password 9 | ) 10 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 11 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 12 | $csvfilepath = "$PSScriptRoot\sqlserver_tables.csv" 13 | $result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql "SELECT TABLE_NAME FROM $database.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" -CommandTimeout 10000 14 | $result | Export-Csv $csvfilepath -NoTypeInformation -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## My PowerShell Scripts 2 | As requested, here is a list of all the scripts I could make generic, and that aren't exclusive to where I work. If you open up a script, I explain what it does in the comments. Also, in general I need to add in some more error checking and verification of success, because normally I am so used to being the only person who uses the script, so I know what not to do. 3 | 4 | *Powershell-Cmdlet-Explorer* lists all installed modules, and by clicking on a module, you can see the cmdlets for that module. When you click on a cmdlet, you can see the help information for it. 5 | 6 | Screenshot: 7 | ![cmdlet screenshot](https://raw.githubusercontent.com/JacFearsome/powershell-scripts/master/screenshots/cmdlet1.png) 8 | 9 | You can check each script's file for a description of what it does. 10 | 11 | That's it! If you have any tips on how to improve these scripts, let me know! 12 | -------------------------------------------------------------------------------- /iis-tools.ps1: -------------------------------------------------------------------------------- 1 | # This script is a quickIIS tool providing restart website and app pool functionality. I plan to add to it as time goes on. 2 | # It uses the SimpleMenu module which can be installed from the Powershell Gallery. 3 | $items = @() 4 | $restart = New-SMMenuItem -Title "Restart App Pool" -Action { 5 | Do { 6 | $apppool = Read-Host "Please enter the name of the app pool" 7 | } 8 | While ($apppool -eq "") 9 | Restart-WebAppPool -Name $apppool -Verbose 10 | } 11 | $items += $restart 12 | $restartWeb = New-SMMenuItem -Title "Restart Website" -Action { 13 | Do { 14 | $website = Read-Host "Please enter the name of the website" 15 | } 16 | While ($website -eq "") 17 | Stop-Website -Name $website -Verbose 18 | Start-Website -Name $website -Verbose 19 | } 20 | $items += $restartWeb 21 | 22 | $menu = New-SMMenu -Title "IIS Tools" -Items $items 23 | 24 | Invoke-SMMenu -Menu $menu -------------------------------------------------------------------------------- /nodejs-forever-start-apps.ps1: -------------------------------------------------------------------------------- 1 | # This script loops through every folder in a directory and starts all the Node.js apps inside them. 2 | # This script is dependent on every one of your Node.js entry point files having the same name, like in this case, server.js 3 | # You also need to have forever or PM2 installed to use lines 12 or 14. 4 | param([Parameter(Mandatory=$true)]$webroot) 5 | # Get list of folders 6 | $folders = Get-ChildItem $webroot 7 | # Loop through folders 8 | foreach ($folder in $folders) { 9 | $foldername = $folder.Name 10 | # Set the current location as the current folder 11 | Set-Location "$webroot\$foldername" 12 | # Start the Node.js app with forever 13 | forever start server.js 14 | # If you use PM2, you can still use the script, just replace the line above with: 15 | # pm2 start server.js 16 | # Or if you want to start the app the old fashioned way 17 | # node server.js 18 | } -------------------------------------------------------------------------------- /create-startup-executable.ps1: -------------------------------------------------------------------------------- 1 | # This script can be used to quickly schedule an executable to be run on start up. In it I assume some basic settings for the sake of simplicity. 2 | param( 3 | [Parameter(Mandatory=$true)] 4 | $name, 5 | [Parameter(Mandatory=$true)] 6 | $exec, 7 | [Parameter(Mandatory=$true)] 8 | $user, 9 | [Parameter(Mandatory=$true)] 10 | $desc 11 | ) 12 | # Create action object 13 | $action = New-ScheduledTaskAction -Execute $exec 14 | # Create trigger object 15 | $trigger = New-ScheduledTaskTrigger -AtStartup 16 | # Create settings object 17 | $settings = New-ScheduledTaskSettingsSet 18 | # Create principal object 19 | $principal = New-ScheduledTaskPrincipal -UserId $user -RunLevel Highest -LogonType ServiceAccount 20 | # Create task object 21 | $task = New-ScheduledTask -Action $action -Description $desc -Principal $principal -Settings $settings -Trigger $trigger 22 | # Register the task 23 | Register-ScheduledTask $name -InputObject $task -------------------------------------------------------------------------------- /create-startup-powershell-script.ps1: -------------------------------------------------------------------------------- 1 | # This script can be used to quickly schedule a powershell script to be run on start up. In it I assume some basic settings for the sake of simplicity. 2 | param( 3 | [Parameter(Mandatory=$true)] 4 | $name, 5 | [Parameter(Mandatory=$true)] 6 | $script, 7 | [Parameter(Mandatory=$true)] 8 | $user, 9 | [Parameter(Mandatory=$true)] 10 | $desc 11 | ) 12 | # Create action object 13 | $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-file $script" 14 | # Create trigger object 15 | $trigger = New-ScheduledTaskTrigger -AtStartup 16 | # Create settings object 17 | $settings = New-ScheduledTaskSettingsSet 18 | # Create principal object 19 | $principal = New-ScheduledTaskPrincipal -UserId $user -RunLevel Highest -LogonType ServiceAccount 20 | # Create task object 21 | $task = New-ScheduledTask -Action $action -Description $desc -Principal $principal -Settings $settings -Trigger $trigger 22 | # Register the task 23 | Register-ScheduledTask $name -InputObject $task -------------------------------------------------------------------------------- /list-gce.ps1: -------------------------------------------------------------------------------- 1 | # This script is a simple menu for listing resources in Google Cloud Platform. In order for this script to work, you must have the GoogleCloud and the SimpleMenu modules installed. 2 | $items = @() 3 | # List VM instances 4 | $gceinstance = New-SMMenuItem -Title "Instances" -Action { 5 | Get-GceInstance | Format-Table 6 | } 7 | $items += $gceinstance 8 | # List VM snapshots 9 | $gcesnapshot = New-SMMenuItem -Title "Snapshots" -Action { 10 | Get-GceSnapshot | Format-Table 11 | } 12 | $items += $gcesnapshot 13 | # List buckets 14 | $gcsbucket = New-SMMenuItem -Title "Buckets" -Action { 15 | Get-GcsBucket | Format-Table 16 | } 17 | $items += $gcsbucket 18 | # List VM disks 19 | $gcedisk = New-SMMenuItem -Title "Disks" -Action { 20 | Get-GceDisk | Format-Table 21 | } 22 | $items += $gcedisk 23 | # List networks 24 | $gcenetwork = New-SMMenuItem -Title "Networks" -Action { 25 | Get-GceNetwork | Format-Table 26 | } 27 | $items += $gcenetwork 28 | 29 | $menu = New-SMMenu -Title "Google Cloud Resources" -Items $items 30 | 31 | Invoke-SMMenu -Menu $menu -------------------------------------------------------------------------------- /file-search.ps1: -------------------------------------------------------------------------------- 1 | # This script serves as a quick Powershell replacement to the search functionality in Windows. 2 | # After you pass in a root folder and a search term, the script will list all files and folders matching that phrase. 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | $path, 6 | [Parameter(Mandatory=$true)] 7 | $term 8 | ) 9 | # Recursive search function 10 | Write-Host "Results:" 11 | function Search-Folder($FilePath, $SearchTerm) { 12 | # Get children 13 | $children = Get-ChildItem -Path $FilePath 14 | # For each child, see if it matches the search term, and if it is a folder, search it too. 15 | foreach ($child in $children) { 16 | $name = $child.Name 17 | if ($name -match $SearchTerm) { 18 | Write-Host "$FilePath\$name" 19 | } 20 | $isdir = Test-Path -Path "$FilePath\$name" -PathType Container 21 | if ($isdir) { 22 | Search-Folder -FilePath "$FilePath\$name" -SearchTerm $SearchTerm 23 | } 24 | } 25 | } 26 | # Call the search function 27 | Search-Folder -FilePath $path -SearchTerm $term -------------------------------------------------------------------------------- /file-watcher.ps1: -------------------------------------------------------------------------------- 1 | # This script watches for a file creation, then executes a powershell script, passing in the created filename. It is meant to be run in task scheduler, and should always be running. 2 | $folder = "" # Specify the full path of the folder you want to watch 3 | $filter = "*" # Specify the file filter (example: *.txt) 4 | 5 | # In the following line, you can change 'IncludeSubdirectories to $true if required. 6 | $fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} 7 | 8 | # Start file watch 9 | Register-ObjectEvent $fsw Created -SourceIdentifier FileWatcher -Action { 10 | $filename = $Event.SourceEventArgs.Name 11 | New-BurntToastNotification -Text "$filename has been created..." -AppLogo $null -Silent 12 | $changeType = $Event.SourceEventArgs.ChangeType 13 | $timeStamp = $Event.TimeGenerated 14 | $app="powershell.exe" 15 | $path="C:\path\to\script.ps1" 16 | $appargs="-file $path -filename $filename" 17 | [Diagnostics.Process]::Start($app,$appargs) 18 | } 19 | -------------------------------------------------------------------------------- /create-cmdlets-js.ps1: -------------------------------------------------------------------------------- 1 | # This script grabs the list of Powershell cmdlets and converts them into a JSON array inside a JavaScript file. In the process it also creates a text file containing the list of cmdlets. 2 | # Useful for if you need to use a list of Powershell cmdlets inside your web app. 3 | # Get the list of Powershell commands. 4 | $commands = Get-Command 5 | # Loop through each command and add the name to a text file 6 | foreach ($command in $commands) { 7 | Add-Content "$PSScriptRoot\cmdlets.txt" $command.Name 8 | } 9 | # Get the content of the newly created text file 10 | $cmdlets = Get-Content "$PSScriptRoot\cmdlets.txt" 11 | # Add the first part of the javascript array to the javascript file 12 | Add-Content "$PSScriptRoot\cmdlets.js" "var cmdlets = [" 13 | # Loop through each line in the cmdlets text file 14 | foreach($line in $cmdlets) { 15 | # Add quotes and a comma 16 | $newline = '"' + $line + '",' 17 | # Add the line to the new javascript file 18 | Add-Content "$PSScriptRoot\cmdlets.js" $newline 19 | } 20 | # Add the array closing tag to the javascript file 21 | Add-Content "$PSScriptRoot\cmdlets.js" "];" -------------------------------------------------------------------------------- /PowerShellHelp/PowershellHelp.ps1: -------------------------------------------------------------------------------- 1 | $commandsList_SelectedIndexChanged = { 2 | [System.Windows.Forms.Cursor]::Current = [System.Windows.Forms.Cursors]::WaitCursor 3 | $selected = $commandsList.SelectedIndex 4 | $cmd = $commandsList.Items[$selected].ToString() 5 | $helpBox.Text = Get-Help $cmd | Out-String 6 | $detailedHelp.Text = Get-Help $cmd -Detailed | Out-String 7 | $examplesBox.Text = Get-Help $cmd -Examples | Out-String 8 | [System.Windows.Forms.Cursor]::Current = [System.Windows.Forms.Cursors]::Default 9 | } 10 | 11 | $MainForm_Load = { 12 | 13 | [System.Windows.Forms.Cursor]::Current = [System.Windows.Forms.Cursors]::WaitCursor 14 | $commands = Get-Command | Sort-Object Name 15 | foreach ($command in $commands) { 16 | $commandsList.Items.Add($command) 17 | } 18 | [System.Windows.Forms.Cursor]::Current = [System.Windows.Forms.Cursors]::Default 19 | $searchBox_TextChanged = { 20 | $commandsList.Items.Clear() 21 | foreach ($item in $commands) { 22 | if ($searchBox.Text -match $item) { 23 | $commandsList.Items.Add($item) 24 | } 25 | } 26 | } 27 | } 28 | 29 | . (Join-Path $PSScriptRoot 'PowershellHelp.designer.ps1') 30 | 31 | $MainForm.ShowDialog() -------------------------------------------------------------------------------- /create-csv-from-mysql-table.ps1: -------------------------------------------------------------------------------- 1 | # Install-Module InvokeQuery 2 | # Run the above command if you do not have this module 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | $server, 6 | [Parameter(Mandatory=$true)] 7 | $database, 8 | [Parameter(Mandatory=$true)] 9 | $dbuser, 10 | [Parameter(Mandatory=$true)] 11 | $dbpass, 12 | [Parameter(Mandatory=$true)] 13 | $query 14 | ) 15 | if (($server -eq "") -or ($server -eq $null)) { 16 | Write-Host "Please specify a server" 17 | } 18 | elif (($database -eq "") -or ($database -eq $null)) { 19 | Write-Host "Please specify a database" 20 | } 21 | elif (($dbuser -eq "") -or ($dbuser -eq $null)) { 22 | Write-Host "Please specify a database user" 23 | } 24 | elif (($dbpass -eq "") -or ($dbpass -eq $null)) { 25 | Write-Host "Please specify a database user password" 26 | } 27 | elif (($query -eq "") -or ($query -eq $null)) { 28 | Write-Host "Please specify a query" 29 | } 30 | else { 31 | $csvfilepath = "$PSScriptRoot\mysql_table.csv" 32 | $result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql $query -CommandTimeout 10000 33 | $result | Export-Csv $csvfilepath -NoTypeInformation 34 | } -------------------------------------------------------------------------------- /AD-passwords-expiring-csv.ps1: -------------------------------------------------------------------------------- 1 | # This script exports a csv with passwords expiring that week 2 | # Declare expiring soon group variable 3 | Import-Module ActiveDirectory 4 | $expiring = @() 5 | # Grab AD Users that are enabled, and select the properties we need 6 | $users = Get-ADUser -Filter {Enabled -eq $true -and PasswordNeverExpires -eq $false} -Properties "DisplayName", "mail", "PasswordLastSet" 7 | # Get max password age 8 | $max = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days 9 | # Loop through every user 10 | foreach ($user in $users) { 11 | # Get the current date 12 | $now = Get-Date 13 | # Create normal date out of msDS-UserPwasswordExpiryTimeComputed property 14 | $expiredate = $user.PasswordLastSet.AddDays($max) 15 | # Create a timespan from the expire date and today's date 16 | $diff = New-TimeSpan $now $expiredate 17 | # If the timespan is less than seven and greater than zero, add the user to the expiring list. 18 | if ($diff.Days -le 7 -and $diff.Days -ge 0) { 19 | $entry = [PSCustomObject]@{ 20 | Name = $user.DisplayName 21 | Email = $user.mail 22 | ExpireDate = $expiredate 23 | } 24 | $expiring += $entry 25 | } 26 | } 27 | # Export the list of expiring passwords to a csv 28 | $expiring | Export-Csv -Path "$PSScriptRoot\expiring_soon.csv" -NoTypeInformation -------------------------------------------------------------------------------- /AD-computers-html-report.ps1: -------------------------------------------------------------------------------- 1 | # This script retrieves all the computers listed in Active Directory and creates an html report. 2 | $reportPath = $PSScriptRoot + "\ActiveDirectoryComputers.html" 3 | # Grab list of computers in Active Directory 4 | $servers = Get-ADComputer -Filter * 5 | # Convert list to HTML 6 | $serversHtml = $servers | Select-Object DNSHostName,Enabled,Name,ObjectClass,ObjectGUID,SamAccountName | ConvertTo-Html -Fragment -PreContent "

Active Directory Computers

" 7 | 8 | # Create HTML file 9 | $head = @" 10 | AD Computer List 11 | 45 | "@ 46 | 47 | # Convert everything to HTML and output to file 48 | ConvertTo-Html -Head $head -Body $serversHtml | Out-File $reportPath -------------------------------------------------------------------------------- /aws-cloudwatch-custom-metrics-config.ps1: -------------------------------------------------------------------------------- 1 | ### This script configures a server for usage with AWS custom CloudWatch metrics. It creates scheduled tasks to run the custom metrics script on a schedule. ### 2 | # Specify path to cloudwatch custom metric script 3 | $path = "C:\path\to\script.ps1" 4 | # Set Execution Policy 5 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force 6 | # Install AWS Powershell Module 7 | Install-Module AWSPowershell -Force 8 | # Create scheduled task for custom CloudWatch metrics 9 | $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-File `"$path`"" 10 | $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 30) 11 | Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "AWSCloudWatch" -Description "Task that reports custom CloudWatch metrics" 12 | # Start AWSCloudWatch task 13 | Start-ScheduledTask -TaskName "AWSCloudWatch" 14 | # Create scheduled task for starting AWSCloudWatch task on startup 15 | $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-Command "Start-ScheduledTask -TaskName AWSCloudWatch' 16 | $trigger = New-ScheduledTaskTrigger -AtStartup 17 | Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "AWSCloudWatchInit" -Description "Starts indefinite repetition of AWSCloudWatch task" -------------------------------------------------------------------------------- /network-tools.ps1: -------------------------------------------------------------------------------- 1 | # This script is a simple menu of quick network tools. However, you must first install the modules in network-tools-install-modules.ps1 2 | $items = @() 3 | # Ping host 4 | $ping = New-SMMenuItem -Title "Ping-Host" -Action { 5 | Do { 6 | $hostname = Read-Host "Please enter the host you want to ping" 7 | } 8 | While ($hostname -eq "") 9 | Ping-Host -ComputerName $host 10 | } 11 | $items += $ping 12 | # Test Url 13 | $test = New-SMMenuItem -Title "Test-Uri" -Action { 14 | Do { 15 | $url = Read-Host "Please enter the url you want to test" 16 | } 17 | While ($url -eq "") 18 | Test-Uri -Uri $url 19 | } 20 | $items += $test 21 | # Scan Ports 22 | $scan = New-SMMenuItem -Title "Start-PortScan" -Action { 23 | Do { 24 | $hostname = Read-Host "Please enter the host you want to scan" 25 | } 26 | While ($hostname -eq "") 27 | Start-PortScan -ComputerName $host 28 | } 29 | $items += $scan 30 | # Invoke Web Request 31 | $invoke = New-SMMenuItem -Title "Invoke-WebRequest" -Action { 32 | Do { 33 | $url = Read-Host "Please enter the url you want to visit" 34 | } 35 | While ($url -eq "") 36 | Invoke-WebRequest -Uri $url 37 | } 38 | $items += $invoke 39 | 40 | $menu = New-SMMenu -Title "Network Tools" -Items $items 41 | 42 | Invoke-SMMenu -Menu $menu -------------------------------------------------------------------------------- /transfer-365-user.ps1: -------------------------------------------------------------------------------- 1 | # This script ties an Office 365 user to a new Actice Directory domain user 2 | # NOTE: This script operates based on the fact that the name of the new AD user and the old AD user are the same. 3 | # NOTE: DirSync must be disabled in order for this script to work 4 | Import-Module MSOnline 5 | # Get admin credentials 6 | $UserCredential = Get-Credential 7 | $DomainCredential = Get-Credential 8 | # Connect to Office 365 9 | Connect-MsolService -Credential $UserCredential 10 | # Grab the AD user to be transferred and the domain controller name or IP 11 | Do { 12 | $destinationPath = Read-Host "AD Domain Username" 13 | } 14 | While ($destinationPath -eq "") 15 | Do { 16 | $server = Read-Host "Domain Controller IP or Hostname" 17 | } 18 | While ($server -eq "") 19 | # Grab the AD user and their GUID 20 | $aduser = Get-ADUser -Identity $user -Server $server -Credential $DomainCredential 21 | $guid = [guid]$aduser.ObjectGUID 22 | $name = $aduser.Name 23 | # Convert the GUID to the ImmutableID 24 | $ImmutableID = [System.Convert]::ToBase64String($guid.ToByteArray()) 25 | # Set the 365's users immutable ID to null 26 | Get-MsolUser -SearchString $name | Set-MsolUser -ImmutableId $null 27 | # Set the 354 users immutable ID to the new one 28 | Get-MsolUser -SearchString $name | Set-MsolUser -ImmutableId $ImmutableID -------------------------------------------------------------------------------- /IIS-delete-website.ps1: -------------------------------------------------------------------------------- 1 | # This script will go and delete the IIS website that you specify, along with the corresponding app pool and DNS entry. 2 | # It is meant to be run from your local computer, so you don't have to log in to your web server and domain controller to delete the website, all you have to do is run the script. 3 | param( 4 | [Parameter(Mandatory=$true)]$webserver, 5 | [Parameter(Mandatory=$true)]$dnsserver 6 | ) 7 | 8 | $sites = Invoke-Command -ComputerName $webserver -ScriptBlock { 9 | $websites = Get-Website 10 | return $websites 11 | } 12 | Write-Host $sites 13 | $todelete = Read-Host "Please type the name of the website you would like to delete (see list above)" 14 | 15 | foreach ($site in $sites) { 16 | if ($todelete -eq $sites.Name) { 17 | Delete-Website($todelete) 18 | } 19 | } 20 | function Delete-Website($name, $webserver, $dnsserver) { 21 | $url = Invoke-Command -ComputerName $webserver -ArgumentList $todelete -ScriptBlock { 22 | param($name) 23 | $url = (Get-Website -Name $name).Bindings.Collection[0].BindingInformation.Split(":")[1] 24 | $apppool = (Get-Website -Name $name).applicationPool 25 | Remove-Website -Name $name 26 | Remove-WebAppPool -Name $apppool 27 | return $url 28 | } 29 | 30 | if (($url -ne "") -and ($url -ne $null)) { 31 | Remove-DnsServerZone -ComputerName $dnsserver -Name $url 32 | } 33 | } -------------------------------------------------------------------------------- /create-csv-from-sqlserver-table.ps1: -------------------------------------------------------------------------------- 1 | # Install-Module InvokeQuery 2 | # Run the above command if you do not have this module 3 | param( 4 | [Parameter(Mandatory=$true)]$server, 5 | [Parameter(Mandatory=$true)]$database, 6 | [Parameter(Mandatory=$true)]$query, 7 | [Parameter(Mandatory=$true)]$username, 8 | [Parameter(Mandatory=$true)]$password 9 | ) 10 | if (($server -eq "") -or ($server -eq $null)) { 11 | Write-Host "Please specify a server" 12 | } 13 | elif (($database -eq "") -or ($database -eq $null)) { 14 | Write-Host "Please specify a database" 15 | } 16 | elif (($username -eq "") -or ($username -eq $null)) { 17 | Write-Host "Please specify a database user" 18 | } 19 | elif (($password -eq "") -or ($password -eq $null)) { 20 | Write-Host "Please specify a database user password" 21 | } 22 | elif (($query -eq "") -or ($query -eq $null)) { 23 | Write-Host "Please specify a query" 24 | } 25 | else { 26 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 27 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 28 | $csvfilepath = "$PSScriptRoot\sqlserver_table.csv" 29 | $result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql $query -CommandTimeout 10000 30 | $result | Export-Csv $csvfilepath -NoTypeInformation 31 | } -------------------------------------------------------------------------------- /ssh-stop-web.ps1: -------------------------------------------------------------------------------- 1 | # This script stops the nginx and php-fpm services on the specified server 2 | param( 3 | [Parameter(Mandatory=$true)]$server, 4 | [Parameter(Mandatory=$true)]$username, 5 | [Parameter(Mandatory=$true)]$password 6 | ) 7 | # Create credential object based on parameters 8 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 9 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 10 | # Create SSH session 11 | $session = New-SSHSession -ComputerName $server -Credential $creds 12 | # Convert entered password to secure string 13 | $secPass = ConvertTo-SecureString $creds.Password -AsPlainText -Force 14 | # Start Shell Stream 15 | $stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) 16 | # Stop nginx and php-fpm 17 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl stop php7.0-fpm" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 18 | Start-Sleep -Seconds 1 19 | $return = $stream.Read() 20 | Write-Host $return 21 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl stop nginx" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 22 | Start-Sleep -Seconds 1 23 | $return = $stream.Read() 24 | Write-Host $return 25 | Remove-SSHSession -SessionId 0 26 | # Finished -------------------------------------------------------------------------------- /ssh-apt-upgrade-ubuntu.ps1: -------------------------------------------------------------------------------- 1 | # This script performs a software update on a Ubuntu or Debian server 2 | param( 3 | [Parameter(Mandatory=$true)] 4 | $server, 5 | [Parameter(Mandatory=$true)] 6 | $username, 7 | [Parameter(Mandatory=$true)] 8 | $password 9 | ) 10 | # Create credential object based on parameters 11 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 12 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 13 | $user = $creds.UserName 14 | # Create SSH session 15 | $session = New-SSHSession -ComputerName $server -Credential $creds 16 | # Start Shell Stream 17 | $stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) 18 | # Run apt=get update 19 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-get update" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 20 | # Wait 30 seconds for apt-get update to run 21 | Start-Sleep -Seconds 30 22 | $return = $stream.Read() 23 | Write-Host $return 24 | # Run apt-get upgrade 25 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-get upgrade" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 26 | # Wait 2 minutes for apt-get upgrade to run 27 | Start-Sleep -Seconds 120 28 | $return = $stream.Read() 29 | Write-Host $return 30 | Remove-SSHSession -SessionId 0 -------------------------------------------------------------------------------- /ssh-start-web.ps1: -------------------------------------------------------------------------------- 1 | # This script starts the nginx and php-fpm services on the specified server 2 | param( 3 | [Parameter(Mandatory=$true)]$server, 4 | [Parameter(Mandatory=$true)]$username, 5 | [Parameter(Mandatory=$true)]$password 6 | ) 7 | # Create credential object based on parameters 8 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 9 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 10 | # Create SSH session 11 | $session = New-SSHSession -ComputerName $server -Credential $creds 12 | # Convert entered password to secure string 13 | $secPass = ConvertTo-SecureString $creds.Password -AsPlainText -Force 14 | # Start Shell Stream 15 | $stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) 16 | # Start nginx and php-fpm 17 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl atart php7.0-fpm" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 18 | Start-Sleep -Seconds 1 19 | $return = $stream.Read() 20 | Write-Host $return 21 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl atart nginx" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 22 | Start-Sleep -Seconds 1 23 | $return = $stream.Read() 24 | Write-Host $return 25 | Remove-SSHSession -SessionId 0 26 | # Finished -------------------------------------------------------------------------------- /ssh-restart-web.ps1: -------------------------------------------------------------------------------- 1 | # This script restarts the nginx and php-fpm services on the specified server 2 | param( 3 | [Parameter(Mandatory=$true)]$server, 4 | [Parameter(Mandatory=$true)]$username, 5 | [Parameter(Mandatory=$true)]$password 6 | ) 7 | # Create credential object based on parameters 8 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 9 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 10 | # Create SSH session 11 | $session = New-SSHSession -ComputerName $server -Credential $creds 12 | # Convert entered password to secure string 13 | $secPass = ConvertTo-SecureString $creds.Password -AsPlainText -Force 14 | # Start Shell Stream 15 | $stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) 16 | # Restart nginx and php-fpm 17 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl restart php7.0-fpm" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 18 | Start-Sleep -Seconds 1 19 | $return = $stream.Read() 20 | Write-Host $return 21 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo systemctl restart nginx" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password 22 | Start-Sleep -Seconds 1 23 | $return = $stream.Read() 24 | Write-Host $return 25 | Remove-SSHSession -SessionId 0 26 | # Finished -------------------------------------------------------------------------------- /hyperv-backup-vm.ps1: -------------------------------------------------------------------------------- 1 | # This script requires some configuration before use. It is was designed to be scheduled in task scheduler. 2 | # This scripts retrieves all virtual machines and exports them to a predefined location every day. It then removes all but the last 7 days of backups. 3 | # You need to set the $backuppath variable to wherever your want to store your VM exports. 4 | 5 | Import-Module Hyper-V 6 | # Enter the full path for the backup folder 7 | $backuppath = "" # Example: "\\backupserver\fileshare\HyperVBackups" 8 | # Get all Hyper-V VMs 9 | $vms = Get-VM 10 | # Grab the current date 11 | $today = Get-Date -Format MM-dd-yy 12 | 13 | foreach ($vm in $vms) { 14 | $vmname = $vm.Name 15 | Write-Host "Backing up $vmname..." 16 | # Create the folders for the backup 17 | New-Item -ItemType Directory -Path "$backuppath\$vmname" # We run this in case it is a new VM. Normally it will fail if the VM folder already exists, which is fine 18 | New-Item -ItemType Directory -Path "$backuppath\$vmname\$today" 19 | # Export the VM 20 | Export-VM -VM $vm -Path "$backuppath\$vmname\$today" 21 | New-BurntToastNotification -Text "$vmname has been exported." -AppLogo $null -Silent 22 | # Remove any backups older than the past 7 days 23 | Get-ChildItem "$backuppath\$vmname" | Sort-Object -Property CreationTime -Descending | Select-Object -Skip 7 | Remove-Item -Recurse 24 | } -------------------------------------------------------------------------------- /ssh-new-db-mongodb.ps1: -------------------------------------------------------------------------------- 1 | # This script creates a new MongoDB database on the Linux host 2 | param( 3 | [Parameter(Mandatory=$true)] 4 | $server, 5 | [Parameter(Mandatory=$true)] 6 | $username, 7 | [Parameter(Mandatory=$true)] 8 | $password, 9 | [Parameter(Mandatory=$true)] 10 | $NEWDB, 11 | [Parameter(Mandatory=$true)] 12 | $NEWUSER, 13 | [Parameter(Mandatory=$true)] 14 | $NEWPWD 15 | ) 16 | # Create credential object based on parameters 17 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 18 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) 19 | $user = $creds.UserName 20 | # Create SSH session 21 | $session = New-SSHSession -ComputerName $server -Credential $creds 22 | # Start Shell Stream 23 | $stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) 24 | # Create database 25 | $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command @" 26 | sudo mongo <Critical Updates" 25 | # Create HTML file 26 | $head = @" 27 | Critical Updates 28 | 59 | "@ 60 | 61 | 62 | # Convert everything to HTML and output to file 63 | ConvertTo-Html -Head $head -Body $updatesHtml | Out-File $reportPath -------------------------------------------------------------------------------- /AD-computers-network-html-report.ps1: -------------------------------------------------------------------------------- 1 | # This script retrieves all the computers listed in Active Directory, tests their network settings, and creates an html report. 2 | # NOTE: test-server.ps1 is included in this directory, and it is required for this script to work. 3 | . "$PSScriptRoot\test-server.ps1" 4 | 5 | $reportPath = $PSScriptRoot + "\ActiveDirectoryComputersNetwork.html" 6 | # Grab list of computers in Active Directory 7 | $servers = Get-ADComputer -Filter * 8 | 9 | $serversNet = @() 10 | 11 | foreach ($server in $servers) { 12 | Write-Host "Testing "$server.DNSHostName 13 | $results = Test-Server -ComputerName $server.DNSHostName 14 | $serversNet += $results 15 | } 16 | 17 | $serversHtml = $serversNet | ConvertTo-Html -Fragment -PreContent "

AD Computers - Network Status

" 18 | 19 | # Create HTML file 20 | $head = @" 21 | AD Computer List 22 | 56 | 57 | 68 | "@ 69 | 70 | $searchbar = @" 71 | 72 | "@ 73 | 74 | # Convert everything to HTML and output to file 75 | ConvertTo-Html -Head $head -Body "$searchbar$serversHtml" | Out-File $reportPath -------------------------------------------------------------------------------- /azure-upload-vhd.ps1: -------------------------------------------------------------------------------- 1 | # This script uploads a vhd to Azure 2 | # Login to Azure 3 | Login-AzureRmAccount 4 | # Ask whether it is a .vhd or .vhdx. If it is a .vhdx, it needs to be converted, because Azure doesn't support .vhdx 5 | Do { 6 | $vhdcheck = Read-Host "Is your virtual drive .vhd or .vhdx? (vhd/vhdx)" 7 | } 8 | While (($vhdcheck -ne "vhd") -and ($vhdcheck -ne "vhdx")) 9 | # If it is a vhd, enter the path of the vhd 10 | if ($vhdcheck -eq "vhd") { 11 | Do { 12 | $destinationPath = Read-Host "Please enter absolute path to VHD (i.e. C:\test.vhd)" 13 | } 14 | While ($pathToVhd -eq "") 15 | # If it is a vhdx, enter the path of the vhdx and the path for the converted vhd, and convert it 16 | } else { 17 | Do { 18 | $pathToVhd = Read-Host "Please enter absolute path to VHDX (i.e. C:\test.vhdx)" 19 | } 20 | While ($pathToVhd -eq "") 21 | Do { 22 | $destinationPath = Read-Host "Please enter absolute path for the converted VHD" 23 | } 24 | While ($destinationPath -eq "") 25 | Write-Host "Converting vhdx to vhd..." 26 | Convert-VHD -Path $pathToVhd -DestinationPath $destinationPath 27 | New-BurntToastNotification -Text "VHDX converted to VHD" -AppLogo $null -Silent 28 | } 29 | # Specify the Azure resource group 30 | Do { 31 | $resourcegroup = Read-Host "Please enter the Azure resource group for the VM" 32 | } 33 | While ($resourcegroup = "") 34 | # Specify the new name of the vhd uploaded to Azure 35 | Do { 36 | $vhdname = Read-Host "Please enter the new name of the VHD in Azure" 37 | } 38 | While ($vhdname = "") 39 | # Specify the url of the blob storage for your Azure subscription 40 | Do { 41 | $url = Read-Host "Please enter the blob storage url in Azure for your subscription (i.e. https://test.blob.core.windows.net/testvhd/)" 42 | } 43 | While ($url = "") 44 | # Create full vhd url 45 | $vhdurl = "$url$vhdname" 46 | # Specify your subscription type 47 | Do { 48 | $subscription = Read-Host "Please enter your subscription type (i.e. Pay-As-You-Go)" 49 | } 50 | While ($subscription = "") 51 | # Get the Azure subscription data 52 | Write-Host "Retrieving Azure subscription..." 53 | Get-AzureRmSubscription –SubscriptionName $subscription | Select-AzureRmSubscription 54 | # Upload the vhd to Azure 55 | Write-Host "Uploading VHD to Azure..." 56 | Add-AzureRmVhd -ResourceGroupName $resourcegroup -LocalFilePath $destinationPath -Destination $vhdurl -OverWrite 57 | New-BurntToastNotification -Text "VHD has been uploaded to Azure" -AppLogo $null -Silent -------------------------------------------------------------------------------- /send-email.ps1: -------------------------------------------------------------------------------- 1 | # This script provides a send-email function that allows you to use it in other scripts to send emails. 2 | # It needs some configuration before use. 3 | # Example usage: 4 | # $from = "person@someplace.com" 5 | # $to = @("person1@someplace.com", person2@someplace.com") 6 | # $cc = @("person3@someplace.com") 7 | # $bcc = @() 8 | # $subject = "An Email Subject" 9 | # $body = "

This is the body

It requires html tags.

" 10 | # $priority = "Normal" # (Options are "Low", "Normal", and "High") 11 | # $attachments = @("C:\path\to\file.txt") 12 | # NOTE: If you are not using a CC, BCC, or attachments, please pass in an empty list, like: 13 | # $attachments = @() 14 | 15 | function Send-Email($subject, $body, $from, $to, $cc, $bcc, $priority, $attachments) { 16 | # Mail Server Settings 17 | $server = "" # Fill this in with the IP of your email server 18 | $serverPort = 25 # Adjust this if needed 19 | 20 | # Set up server connection 21 | $smtpClient = New-Object System.Net.Mail.SmtpClient($server, $serverPort) 22 | $smtpClient.UseDefaultCredentials = $true 23 | 24 | # Create email message 25 | $message = New-Object System.Net.Mail.MailMessage 26 | $message.Subject = $subject 27 | $message.Body = $body 28 | $message.IsBodyHtml = $true 29 | $message.From = $from 30 | 31 | # If there are to recipients, add them 32 | if ($to.count -gt 0) { 33 | foreach ($person in $to) { 34 | $message.To.Add($person) 35 | } 36 | } 37 | 38 | # If there are CC recipients, add them 39 | if ($cc.count -gt 0) { 40 | foreach ($person in $cc) { 41 | $message.CC.Add($person) 42 | } 43 | } 44 | 45 | # If there are BCC recipients, add them 46 | if ($bcc.count -gt 0) { 47 | foreach ($person in $bcc) { 48 | $message.BCC.Add($person) 49 | } 50 | } 51 | 52 | # If there are attachments, add them 53 | if ($attachments.count -gt 0) 54 | { 55 | foreach ($file in $attachments) 56 | { 57 | $extension=(((Get-ChildItem -Path $file.FilePath).extension).toupper()) 58 | switch ($extension) 59 | { 60 | ".GIF" {$ContentType="Image/gif"} 61 | ".JPG" {$ContentType="Image/jpeg"} 62 | ".JPEG" {$ContentType="Image/jpeg"} 63 | ".PNG" {$ContentType="Image/png"} 64 | ".CSV" {$ContentType="text/csv"} 65 | ".TXT" {$ContentType="text/plain"} 66 | } 67 | $attachments=@() 68 | $Attachments+=(New-Object System.Net.Mail.Attachment($File.FilePath,$ContentType)) 69 | if ($file.ContentID -ne $null) { $attachments[-1].ContentID=$file.ContentID } 70 | if ($ContentType.Substring(0,4) -eq "text") { $attachments[-1].ContentDisposition.FileName=(((Get-ChildItem -Path $file.FilePath).Name)) } 71 | $MailMessage.Attachments.Add($Attachments[-1]) 72 | } 73 | } 74 | 75 | $smtpClient.Send($message) 76 | New-BurntToastNotification -Text "Email has been sent" -AppLogo $null -Silent 77 | } -------------------------------------------------------------------------------- /plex-manufacturing-cloud.ps1: -------------------------------------------------------------------------------- 1 | ### Plex Manufacturing Cloud PowerShell Module ### 2 | # Plex Manufacturing Cloud is an cloud-based ERP software used in manufacturing 3 | # Example Usage: 4 | # First, create a PSObject with all the properties you need for the data source. If you aren't using an input parameter, you don't have to include it. 5 | # $props = @{ 6 | # 'Part_No'="" 7 | # } 8 | # $wsobj = New-Object -TypeName PSObject -Property $props 9 | # Then connect to Plex with your credentials and specify if it is test 10 | # $service = ConnectTo-Plex -username "CompanyWs@plex.com" -password "" -isTest $false 11 | # Then retrieve the web service objects after passing in the web service variable, the Plex datasource key, and the object you created with the parameters. 12 | # $objects = Get-WebServiceObjects -service $service -datasourceKey 123 -object $wsobj 13 | # The above function will either return an error message if something went wrong, or the results, converted to a collection of PSObjects. 14 | 15 | # First function connects to Plex and creates a web service object, which is used in the Get-WebServiceObjects function 16 | function ConnectTo-Plex($username, $password, $isTest) { 17 | # If $isTest is $true, use test database 18 | if ($isTest -eq $true) { 19 | $url = "https://testapi.plexonline.com/DataSource/Service.asmx?WSDL" 20 | # Otherwise, use the normal database 21 | } else { 22 | $url = "https://api.plexonline.com/DataSource/Service.asmx?WSDL" 23 | } 24 | # Convert password to secure string 25 | $secpass = ConvertTo-SecureString $password -AsPlainText -Force 26 | # Create credential object 27 | $creds = New-Object System.Management.Automation.PSCredential ($username, $secpass) 28 | # Create and return web service object 29 | $ws = New-WebServiceProxy -Uri $url -Credential $creds 30 | return $ws 31 | } 32 | 33 | # The second function makes the web service call and then converts the result 34 | function Get-WebServiceObjects($service, [int]$datasourceKey, [PSObject]$object) { 35 | # Declare input keys and values variables 36 | $inputkeys = "" 37 | $inputvalues = "" 38 | # Loop through properties on parameter object and create delimited strings out of it 39 | $object.PSObject.Properties | ForEach-Object { 40 | $inputkeys = $inputkeys, ("@" + $_.Name) -join "," 41 | $inputvalues = $inputvalues, $_.Value -join "," 42 | } 43 | # Make the actual web service call 44 | $result = $service.ExecuteDataSourcePost($datasourceKey, $inputkeys, $inputvalues, ",") 45 | # If there is an error, return it instead of continuing. 46 | if ($result.Error -eq $true) { 47 | return $result.Message 48 | # Otherwise, loop through results set and create a PSObject out of the SOAP response 49 | } else { 50 | $objList = @() 51 | foreach ($res in $result.ResultSets) { 52 | foreach ($row in $res.Rows) { 53 | $props = @{} 54 | foreach($col in $row.Columns) { 55 | $colname = $col.Name 56 | $colval = $col.Value 57 | $props[$colname] = $colval 58 | } 59 | $resultObj = New-Object -TypeName PSObject -Property $props 60 | $objList += $resultObj 61 | } 62 | } 63 | return $objList 64 | } 65 | } -------------------------------------------------------------------------------- /system-info-local-json.ps1: -------------------------------------------------------------------------------- 1 | # This script grabs system information on the local computer, converts it into a json object, and writes it to a file. 2 | # The resulting json file can be used in many ways, like a web app. 3 | 4 | # RAM 5 | $RAM = Get-WmiObject -Query "SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem" 6 | 7 | $totalRAM = [math]::Round($RAM.TotalVisibleMemorySize/1MB, 2) 8 | $freeRAM = [math]::Round($RAM.FreePhysicalMemory/1MB, 2) 9 | $usedRAM = [math]::Round(($RAM.TotalVisibleMemorySize - $RAM.FreePhysicalMemory)/1MB, 2) 10 | 11 | # Operating System 12 | $OS = Get-WmiObject -class Win32_OperatingSystem 13 | 14 | $OS_Name = $OS.Caption 15 | $OS_InstallDate = $OS.ConvertToDateTime($OS.InstallDate) 16 | $OS_LastBootUpTime = $OS.ConvertToDateTime($OS.LastBootUpTime) 17 | $OS_Architecture = $OS.OSArchitecture 18 | $OS_SystemDrive = $OS.SystemDrive 19 | $OS_WindowsDirectory = $OS.WindowsDirectory 20 | $OS_BuildNumber = $OS.BuildNumber 21 | $OS_SerialNumber = $OS.SerialNumber 22 | $OS_Version = $OS.Version 23 | $OS_Manufacturer = $OS.Manufacturer 24 | 25 | # Computer System 26 | $CS = Get-WmiObject -class Win32_ComputerSystem 27 | 28 | $CS_Name = $CS.Name 29 | $CS_Owner = $CS.PrimaryOwnerName 30 | 31 | # CPU 32 | $CPU = Get-WmiObject -class Win32_Processor 33 | 34 | $CPU_Name = $CPU.Name 35 | $CPU_Manufacturer = $CPU.Manufacturer 36 | $CPU_MaxClockSpeed = $CPU.MaxClockSpeed / 1000 37 | $CPU_Used = (Get-WmiObject win32_processor).LoadPercentage 38 | $CPU_Free = 100 - $CPU_Used 39 | 40 | # Disk 41 | $Disk = Get-WmiObject -class Win32_LogicalDisk -Filter "DeviceID='C:'" 42 | $Disk_ID = $Disk.DeviceID 43 | $Disk_TotalSpace = [math]::Round($Disk.Size/1GB, 2) 44 | $Disk_FreeSpace = [math]::Round($Disk.FreeSpace/1GB, 2) 45 | $Disk_UsedSpace = [math]::Round(($Disk.Size - $Disk.FreeSpace)/1GB, 2) 46 | 47 | # System Info 48 | $systeminfo = systeminfo 49 | 50 | # IP Config 51 | $ipconfig = ipconfig 52 | 53 | # Driver Query 54 | $driverquery = driverquery 55 | 56 | # Running Services 57 | $netstart = net start 58 | 59 | # Create info object 60 | $infoprop = @{ 61 | 'RAM_total'= $totalRAM; 62 | 'RAM_free'= $freeRAM; 63 | 'RAM_used'= $usedRAM; 64 | 'OS_Name'= $OS_Name; 65 | 'OS_InstallDate'= $OS_InstallDate; 66 | 'OS_LastBootUpTime'= $OS_LastBootUpTime; 67 | 'OS_Architecture'= $OS_Architecture; 68 | 'OS_SystemDrive'= $OS_SystemDrive; 69 | 'OS_WindowsDirectory'= $OS_WindowsDirectory; 70 | 'OS_BuildNumber'= $OS_BuildNumber; 71 | 'OS_SerialNumber'= $OS_SerialNumber; 72 | 'OS_Version'= $OS_Version; 73 | 'OS_Manufacturer'= $OS_Manufacturer; 74 | 'CS_Name'= $CS_Name; 75 | 'CS_Owner'= $CS_Owner; 76 | 'CPU_Name'= $CPU_Name; 77 | 'CPU_Manufacturer'= $CPU_Manufacturer; 78 | 'CPU_MaxClockSpeed'= $CPU_MaxClockSpeed; 79 | 'CPU_Used'= $CPU_Used; 80 | 'CPU_Free'= $CPU_Free; 81 | 'Disk_ID'= $Disk_ID; 82 | 'Disk_TotalSpace'= $Disk_TotalSpace; 83 | 'Disk_FreeSpace'= $Disk_FreeSpace; 84 | 'Disk_UsedSpace'= $Disk_UsedSpace; 85 | 'systeminfo'= $systeminfo; 86 | 'ipconfig'= $ipconfig; 87 | 'driverquery'= $driverquery; 88 | 'netstart'= $netstart; 89 | } 90 | 91 | $info = New-Object -TypeName PSObject -Prop $infoprop 92 | 93 | # Convert info to JSON 94 | $info = $info | ConvertTo-JSON 95 | 96 | # Output to JSON file 97 | $info | Out-File "$PSScriptRoot\info.json" -Encoding "UTF8" 98 | -------------------------------------------------------------------------------- /aws-cloudwatch-custom-metrics.ps1: -------------------------------------------------------------------------------- 1 | ### This script creates custom CloudWatch metrics in AWS and sends metric data ### 2 | # Fill $param, $namespace, and $instanceID with the proper values # 3 | Import-Module AWSPowerShell 4 | # AWS Defaults data 5 | $param = @{ 6 | region = ''; 7 | AccessKey = ''; 8 | SecretKey = ''; 9 | } 10 | # Initialize AWS 11 | Initialize-AWSDefaults @param -Verbose 12 | # Instance and namespace variables 13 | $namespace = "" 14 | $instanceID = "" 15 | 16 | # Memory 17 | $ram = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize)/1MB, 2) 18 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 19 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 20 | $dim.Name = "instanceID" 21 | $dim.Value = $instanceID 22 | $data.Dimensions = $dim 23 | $data.Timestamp = (Get-Date).ToUniversalTime() 24 | $data.MetricName = "Total Memory" 25 | $data.Unit = "Gigabytes" 26 | $data.Value = "$($ram)" 27 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 28 | 29 | $free = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select-Object -ExpandProperty FreePhysicalMemory)/1MB, 2) 30 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 31 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 32 | $dim.Name = "instanceID" 33 | $dim.Value = $instanceID 34 | $data.Dimensions = $dim 35 | $data.Timestamp = (Get-Date).ToUniversalTime() 36 | $data.MetricName = "Free Memory" 37 | $data.Unit = "Gigabytes" 38 | $data.Value = "$($free)" 39 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 40 | 41 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 42 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 43 | $dim.Name = "instanceID" 44 | $dim.Value = $instanceID 45 | $data.Dimensions = $dim 46 | $data.Timestamp = (Get-Date).ToUniversalTime() 47 | $data.MetricName = "Memory Usage" 48 | $data.Unit = "Percent" 49 | $data.Value = "$((($ram - $free) / $ram) * 100)" 50 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 51 | 52 | # Disk 53 | $disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object @{Label="DriveLetter"; Expression={$_.DeviceID}},@{Label="Name"; Expression={$_.VolumeName}},@{Label="Free"; Expression={“{0:N2}” -f ($_.FreeSpace / 1GB)}},@{Label="Total"; Expression={“{0:N2}” -f ($_.Size / 1GB)}} 54 | foreach ($disk in $disks) { 55 | $drive = $disk.DriveLetter 56 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 57 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 58 | $dim.Name = "instanceID" 59 | $dim.Value = $instanceID 60 | $data.Dimensions = $dim 61 | $data.Timestamp = (Get-Date).ToUniversalTime() 62 | $data.Unit = "Gigabytes" 63 | $data.Value = "$($disk.Total)" 64 | $data.MetricName = "$drive Total" 65 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 66 | 67 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 68 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 69 | $dim.Name = "instanceID" 70 | $dim.Value = $instanceID 71 | $data.Dimensions = $dim 72 | $data.Timestamp = (Get-Date).ToUniversalTime() 73 | $data.Unit = "Gigabytes" 74 | $data.Value = "$($disk.Free)" 75 | $data.MetricName = "$drive Free" 76 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 77 | 78 | $data = New-Object Amazon.CloudWatch.Model.MetricDatum 79 | $dim = New-Object Amazon.CloudWatch.Model.Dimension 80 | $dim.Name = "instanceID" 81 | $dim.Value = $instanceID 82 | $data.Dimensions = $dim 83 | $data.Timestamp = (Get-Date).ToUniversalTime() 84 | $data.MetricName = "$drive Usage" 85 | $data.Unit = "Percent" 86 | $data.Value = "$((($disk.Total - $disk.Free) / $disk.Total) * 100)" 87 | Write-CWMetricData -Namespace $namespace -MetricData $data -Verbose 88 | } -------------------------------------------------------------------------------- /test-server.ps1: -------------------------------------------------------------------------------- 1 | # This is not my original work, I downloaded it to use with GetFailed.ps1 2 | Function Test-Server{ 3 | [cmdletBinding()] 4 | param( 5 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 6 | [string[]]$ComputerName, 7 | [parameter(Mandatory=$false)] 8 | [switch]$CredSSP, 9 | [Management.Automation.PSCredential] $Credential) 10 | 11 | begin{ 12 | $total = Get-Date 13 | $results = @() 14 | if($credssp){if(!($credential)){Write-Host "must supply Credentials with CredSSP test";break}} 15 | } 16 | process{ 17 | foreach($name in $computername) 18 | { 19 | $dt = $cdt= Get-Date 20 | Write-verbose "Testing: $Name" 21 | $failed = 0 22 | try{ 23 | $DNSEntity = [Net.Dns]::GetHostEntry($name) 24 | $domain = ($DNSEntity.hostname).replace("$name.","") 25 | $ips = $DNSEntity.AddressList | %{$_.IPAddressToString} 26 | } 27 | catch 28 | { 29 | $rst = "" | select Name,IP,Domain,Ping,WSMAN,CredSSP,RemoteReg,RPC,RDP 30 | $rst.name = $name 31 | $results += $rst 32 | $failed = 1 33 | } 34 | Write-verbose "DNS: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 35 | if($failed -eq 0){ 36 | foreach($ip in $ips) 37 | { 38 | 39 | $rst = "" | select Name,IP,Domain,Ping,WSMAN,CredSSP,RemoteReg,RPC,RDP 40 | $rst.name = $name 41 | $rst.ip = $ip 42 | $rst.domain = $domain 43 | ####RDP Check (firewall may block rest so do before ping 44 | try{ 45 | $socket = New-Object Net.Sockets.TcpClient($name, 3389) 46 | if($socket -eq $null) 47 | { 48 | $rst.RDP = $false 49 | } 50 | else 51 | { 52 | $rst.RDP = $true 53 | $socket.close() 54 | } 55 | } 56 | catch 57 | { 58 | $rst.RDP = $false 59 | } 60 | Write-verbose "RDP: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 61 | #########ping 62 | if(test-connection $ip -count 1 -Quiet) 63 | { 64 | Write-verbose "PING: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 65 | $rst.ping = $true 66 | try{############wsman 67 | Test-WSMan $ip | Out-Null 68 | $rst.WSMAN = $true 69 | } 70 | catch 71 | {$rst.WSMAN = $false} 72 | Write-verbose "WSMAN: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 73 | if($rst.WSMAN -and $credssp) ########### credssp 74 | { 75 | try{ 76 | Test-WSMan $ip -Authentication Credssp -Credential $cred 77 | $rst.CredSSP = $true 78 | } 79 | catch 80 | {$rst.CredSSP = $false} 81 | Write-verbose "CredSSP: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 82 | } 83 | try ########remote reg 84 | { 85 | [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $ip) | Out-Null 86 | $rst.remotereg = $true 87 | } 88 | catch 89 | {$rst.remotereg = $false} 90 | Write-verbose "remote reg: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 91 | try ######### wmi 92 | { 93 | $w = [wmi] '' 94 | $w.psbase.options.timeout = 15000000 95 | $w.path = "\\$Name\root\cimv2:Win32_ComputerSystem.Name='$Name'" 96 | $w | select none | Out-Null 97 | $rst.RPC = $true 98 | } 99 | catch 100 | {$rst.rpc = $false} 101 | Write-verbose "WMI: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 102 | } 103 | else 104 | { 105 | $rst.ping = $false 106 | $rst.wsman = $false 107 | $rst.credssp = $false 108 | $rst.remotereg = $false 109 | $rst.rpc = $false 110 | } 111 | $results += $rst 112 | }} 113 | Write-Verbose "Time for $($Name): $((New-TimeSpan $cdt ($dt)).totalseconds)" 114 | Write-Verbose "----------------------------" 115 | } 116 | } 117 | end{ 118 | Write-Verbose "Time for all: $((New-TimeSpan $total ($dt)).totalseconds)" 119 | Write-Verbose "----------------------------" 120 | return $results 121 | } 122 | } -------------------------------------------------------------------------------- /system-info-html-report-local.ps1: -------------------------------------------------------------------------------- 1 | # This script grabs system information using WMI and outputs it to a HTML report 2 | # File paths 3 | $reportPath = $PSScriptRoot + "\report.html" 4 | $date = Get-Date 5 | # Computer info 6 | $ram = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty TotalVisibleMemorySize)/1MB, 2) 7 | $free = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty FreePhysicalMemory)/1MB, 2) 8 | $name = Get-WmiObject Win32_ComputerSystem | Select -ExpandProperty Name 9 | $numProcesses = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfProcesses 10 | $numUsers = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfUsers 11 | $boot = Get-WmiObject Win32_OperatingSystem | Select-Object @{Label="LastBootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} | Select -ExpandProperty LastBootTime 12 | $os = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty Caption 13 | $arch = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty OSArchitecture 14 | $processor = Get-WmiObject Win32_Processor | Select -ExpandProperty Name 15 | $model = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Name 16 | $manufacturer = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Vendor 17 | 18 | # Create computer object and html 19 | $computerProps = @{ 20 | 'Name'= $name; 21 | 'Operating System'= $os; 22 | 'Architecture'= $arch; 23 | 'Processor'= $processor; 24 | 'Model Name'=$model; 25 | 'Manufacturer'=$manufacturer; 26 | 'Last Boot'= $boot 27 | } 28 | $computer = New-Object -TypeName PSObject -Prop $computerProps 29 | $computerHtml = $computer | ConvertTo-Html -Fragment -PreContent "

Computer Report - $date

System Information

" 30 | 31 | # Create computer object and html 32 | $perfmonProps = @{ 33 | 'Free Memory (GB)'= $free; 34 | 'Total Memory (GB)'= $ram; 35 | 'Process Count'=$numProcesses; 36 | 'User Count'=$numUsers 37 | } 38 | $perfmon = New-Object -TypeName PSObject -Prop $perfmonProps 39 | $perfmonHtml = $perfmon | ConvertTo-Html -Fragment -PreContent "

Performance Information

" 40 | 41 | # List network stats 42 | $ips = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,@{Label="IP Address"; Expression={($_.IPAddress[0])}},@{Label="Default Gateway"; Expression={($_.DefaultIPGateway[0])}},MACAddress 43 | $ipsHtml = $ips | ConvertTo-Html -Fragment -PreContent "

Network Information

" 44 | 45 | # List drive stats 46 | $disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object @{Label="Drive Letter"; Expression={$_.DeviceID}},@{Label="Name"; Expression={$_.VolumeName}},@{Label="Free (GB)"; Expression={“{0:N2}” -f ($_.FreeSpace / 1GB)}},@{Label="Total (GB)"; Expression={“{0:N2}” -f ($_.Size / 1GB)}} 47 | $disksHtml = $disks | ConvertTo-Html -Fragment -PreContent "

Drives

" 48 | 49 | # Select all processes that are over 50 MB 50 | $processes = Get-WmiObject Win32_Process | Where-Object {$_.WorkingSetSize -gt 52428800} | Sort-Object WorkingSetSize -Descending | Select-Object Name,ProcessId,@{Label="Memory Usage (MB)"; Expression={“{0:N2}” -f ($_.WorkingSetSize / 1MB)}} 51 | $processesHtml = $processes | ConvertTo-Html -Fragment -PreContent "

Runnning Processes over 50MB

" 52 | 53 | # Select all running services 54 | $services= Get-WmiObject Win32_Service | Where-Object {$_.State -eq "Running"} | Sort-Object DisplayName | Select-Object DisplayName,ProcessId,StartMode 55 | $servicesHtml = $services | ConvertTo-Html -Fragment -PreContent "

Running Services

" 56 | 57 | # Select all start up programs 58 | $startup= Get-WmiObject Win32_startupCommand | Sort-Object Caption | Select-Object Caption,User,Command 59 | $startupHtml = $startup | ConvertTo-Html -Fragment -PreContent "

Startup Commands

" 60 | 61 | # Create HTML file 62 | $head = @" 63 | Computer Report 64 | 98 | "@ 99 | # Convert everything to HTML and output to file 100 | ConvertTo-Html -Head $head -Body "$computerHtml $perfmonHtml $ipsHtml $disksHtml $processesHtml $servicesHtml $startupHtml" | Out-File $reportPath -------------------------------------------------------------------------------- /flancy-sys-info-ws.ps1: -------------------------------------------------------------------------------- 1 | # This script starts a simple web service server that allows you to remotely manage your computer. It is mostly a proof of concept script, showing the potential of tools like flancy 2 | # Flancy GitHub: https://github.com/toenuff/flancy 3 | 4 | Import-Module "C:\path\to\flancy\module" 5 | 6 | $head = @" 7 | flancy Web Services 8 | 39 | "@ 40 | 41 | # Set the port you want to run flancy on 42 | $url = "http://localhost:8000" 43 | 44 | New-Flancy -url $url -WebSchema @( 45 | # Show the hostname at the root url 46 | Get '/' { hostname } 47 | # Start a process 48 | Get '/startprocess/{exec}' { 49 | $results = Start-Process -FilePath $parameters.exec 50 | $results | ConvertTo-Json 51 | } 52 | # Start a service 53 | Get '/startservice/{exec}' { 54 | $results = Start-Service $parameters.exec 55 | $results | ConvertTo-Json 56 | } 57 | # Install a package 58 | Get '/install/{package}' { 59 | $results = Install-Package -Name $parameters.package 60 | $results | ConvertTo-Json 61 | } 62 | # Show system information 63 | Get '/sysinfo' { 64 | $name = Get-WmiObject Win32_ComputerSystem | Select -ExpandProperty Name 65 | $boot = Get-WmiObject Win32_OperatingSystem | Select-Object @{Label="LastBootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} | Select -ExpandProperty LastBootTime 66 | $os = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty Caption 67 | $arch = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty OSArchitecture 68 | $processor = Get-WmiObject Win32_Processor | Select -ExpandProperty Name 69 | $model = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Name 70 | $manufacturer = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Vendor 71 | $computerProps = @{ 72 | 'Name'= $name; 73 | 'Operating System'= $os; 74 | 'Architecture'= $arch; 75 | 'Processor'= $processor; 76 | 'Model Name'=$model; 77 | 'Manufacturer'=$manufacturer; 78 | 'Last Boot'= $boot 79 | } 80 | $computerProps | ConvertTo-Html -Head $head 81 | } 82 | # Show performance information 83 | Get '/perfmoninfo' { 84 | $ram = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty TotalVisibleMemorySize)/1MB, 2) 85 | $free = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty FreePhysicalMemory)/1MB, 2) 86 | $numProcesses = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfProcesses 87 | $numUsers = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfUsers 88 | $perfmonProps = @{ 89 | 'Free Memory (GB)'= $free; 90 | 'Total Memory (GB)'= $ram; 91 | 'Process Count'=$numProcesses; 92 | 'User Count'=$numUsers 93 | } 94 | $perfmonProps | ConvertTo-Html -Head $head 95 | } 96 | # Show network information 97 | Get '/network' { 98 | $ips = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,@{Label="IP Address"; Expression={($_.IPAddress[0])}},@{Label="Default Gateway"; Expression={($_.DefaultIPGateway[0])}},MACAddress 99 | $ips | ConvertTo-Html -Head $head 100 | } 101 | # Show drive information 102 | Get '/drives' { 103 | $disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object @{Label="Drive Letter"; Expression={$_.DeviceID}},@{Label="Name"; Expression={$_.VolumeName}},@{Label="Free (GB)"; Expression={“{0:N2}” -f ($_.FreeSpace / 1GB)}},@{Label="Total (GB)"; Expression={“{0:N2}” -f ($_.Size / 1GB)}} 104 | $disks | ConvertTo-Html -Head $head 105 | } 106 | # Show running processes 107 | Get '/processes' { 108 | $processes = Get-WmiObject Win32_Process | Where-Object {$_.WorkingSetSize -gt 52428800} | Sort-Object WorkingSetSize -Descending | Select-Object Name,ProcessId,@{Label="Memory Usage (MB)"; Expression={“{0:N2}” -f ($_.WorkingSetSize / 1MB)}} $ips | ConvertTo-Html -Head $head 109 | $processes | ConvertTo-Html -Head $head 110 | } 111 | # Show running services 112 | Get '/services' { 113 | $services= Get-WmiObject Win32_Service | Where-Object {$_.State -eq "Running"} | Sort-Object DisplayName | Select-Object DisplayName,ProcessId,StartMode 114 | $services | ConvertTo-Html -Head $head 115 | } 116 | # Show start up programs 117 | Get '/startup' { 118 | $startup = Get-WmiObject Win32_startupCommand | Sort-Object Caption | Select-Object Caption,User,Command 119 | $startup | ConvertTo-Html -Head $head 120 | } 121 | ) -------------------------------------------------------------------------------- /server-system-info-website.ps1: -------------------------------------------------------------------------------- 1 | # This script grabs system information using WMI for each server listed in servers.txt and outputs it into the web root of a website. 2 | # Import list of servers 3 | $servers = Get-Content "servers.txt" 4 | # Specify the path to the webroot here 5 | $webroot = "" # example: \\webserver\c$\inetpub\wwwroot 6 | $indexpath = "$webroot\index.html" 7 | 8 | # Create HTML header 9 | $head = @" 10 | Server Report 11 | 50 | "@ 51 | 52 | # Create index.html 53 | $indexHtml = "" 54 | $indexHtml += "

Server Health Report

" 55 | $indexHtml += "" 56 | foreach ($server in $servers) { 57 | $indexHtml += "" 58 | } 59 | $indexHtml += "
Server Name
$server
" 60 | ConvertTo-Html -Head $head -Body $indexHtml | Out-File $indexpath 61 | 62 | # Loop through servers 63 | foreach ($server in $servers) { 64 | # Create file path 65 | $filepath = "$webroot\$server.html" 66 | # Get date 67 | $date = Get-Date 68 | # Computer info 69 | $ram = [math]::Round((Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty TotalVisibleMemorySize)/1MB, 2) 70 | $name = Get-WmiObject -ComputerName $server Win32_ComputerSystem | Select -ExpandProperty Name 71 | $boot = Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select-Object @{Label="LastBootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} | Select -ExpandProperty LastBootTime 72 | $os = Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty Caption 73 | $arch = Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty OSArchitecture 74 | $processor = Get-WmiObject -ComputerName $server Win32_Processor | Select -ExpandProperty Name 75 | $free = [math]::Round((Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty FreePhysicalMemory)/1MB, 2) 76 | $numProcesses = Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty NumberOfProcesses 77 | $numUsers = Get-WmiObject -ComputerName $server Win32_OperatingSystem | Select -ExpandProperty NumberOfUsers 78 | $model = Get-WmiObject -ComputerName $server win32_ComputerSystemProduct | Select -ExpandProperty Name 79 | $manufacturer = Get-WmiObject -ComputerName $server win32_ComputerSystemProduct | Select -ExpandProperty Vendor 80 | 81 | # Create computer object and html 82 | $computerProps = @{ 83 | 'Name'= $name; 84 | 'Operating System'= $os; 85 | 'Architecture'= $arch; 86 | 'Processor'= $processor; 87 | 'Model Name'=$model; 88 | 'Manufacturer'=$manufacturer; 89 | 'Last Boot'= $boot 90 | } 91 | $computer = New-Object -TypeName PSObject -Prop $computerProps 92 | $computerHtml = $computer | ConvertTo-Html -Fragment -PreContent "

$server Report - $date

System Information

" 93 | 94 | # Create computer object and html 95 | $perfmonProps = @{ 96 | 'Free Memory (GB)'= $free; 97 | 'Total Memory (GB)'= $ram; 98 | 'Process Count'=$numProcesses; 99 | 'User Count'=$numUsers 100 | } 101 | $perfmon = New-Object -TypeName PSObject -Prop $perfmonProps 102 | $perfmonHtml = $perfmon | ConvertTo-Html -Fragment -PreContent "

Performance Information

" 103 | 104 | # List network stats 105 | $ips = Get-WmiObject -ComputerName $server Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,@{Label="IP Address"; Expression={($_.IPAddress[0])}},@{Label="Default Gateway"; Expression={($_.DefaultIPGateway[0])}},MACAddress 106 | $ipsHtml = $ips | ConvertTo-Html -Fragment -PreContent "

Network Information

" 107 | 108 | # List drive stats 109 | $disks = Get-WmiObject -ComputerName $server Win32_LogicalDisk -Filter "DriveType=3" | Select-Object @{Label="Drive Letter"; Expression={$_.DeviceID}},@{Label="Name"; Expression={$_.VolumeName}},@{Label="Free (GB)"; Expression={“{0:N2}” -f ($_.FreeSpace / 1GB)}},@{Label="Total (GB)"; Expression={“{0:N2}” -f ($_.Size / 1GB)}} 110 | $disksHtml = $disks | ConvertTo-Html -Fragment -PreContent "

Drives

" 111 | 112 | # Select all processes that are over 50 MB 113 | $processes = Get-WmiObject -ComputerName $server Win32_Process | Where-Object {$_.WorkingSetSize -gt 52428800} | Sort-Object WorkingSetSize -Descending | Select-Object Name,ProcessId,@{Label="Memory Usage (MB)"; Expression={“{0:N2}” -f ($_.WorkingSetSize / 1MB)}} 114 | $processesHtml = $processes | ConvertTo-Html -Fragment -PreContent "

Runnning Processes over 50MB

" 115 | 116 | # Select all running services 117 | $services= Get-WmiObject -ComputerName $server Win32_Service | Where-Object {$_.State -eq "Running"} | Sort-Object DisplayName | Select-Object DisplayName,ProcessId,StartMode 118 | $servicesHtml = $services | ConvertTo-Html -Fragment -PreContent "

Running Services

" 119 | 120 | # Select all start up programs 121 | $startup= Get-WmiObject -ComputerName $server Win32_startupCommand | Sort-Object Caption | Select-Object Caption,User,Command 122 | $startupHtml = $startup | ConvertTo-Html 123 | 124 | # Convert everything to HTML and output to file 125 | ConvertTo-Html -Head $head -Body "$computerHtml $perfmonHtml $ipsHtml $disksHtml $processesHtml $servicesHtml $startupHtml" | Out-File $filepath 126 | } -------------------------------------------------------------------------------- /PowerShellHelp/PowershellHelp.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PowerShellHelp/PowershellHelp.designer.ps1: -------------------------------------------------------------------------------- 1 | [void][System.Reflection.Assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') 2 | [void][System.Reflection.Assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') 3 | $MainForm = New-Object -TypeName System.Windows.Forms.Form 4 | [System.Windows.Forms.ListBox]$commandsList = $null 5 | [System.Windows.Forms.TextBox]$helpBox = $null 6 | [System.Windows.Forms.TabControl]$tabControl1 = $null 7 | [System.Windows.Forms.TabPage]$tabPage1 = $null 8 | [System.Windows.Forms.TabPage]$tabPage2 = $null 9 | [System.Windows.Forms.TextBox]$detailedHelp = $null 10 | [System.Windows.Forms.TabPage]$tabPage3 = $null 11 | [System.Windows.Forms.TextBox]$examplesBox = $null 12 | [System.Windows.Forms.Button]$button1 = $null 13 | function InitializeComponent 14 | { 15 | $commandsList = (New-Object -TypeName System.Windows.Forms.ListBox) 16 | $helpBox = (New-Object -TypeName System.Windows.Forms.TextBox) 17 | $tabControl1 = (New-Object -TypeName System.Windows.Forms.TabControl) 18 | $tabPage1 = (New-Object -TypeName System.Windows.Forms.TabPage) 19 | $tabPage2 = (New-Object -TypeName System.Windows.Forms.TabPage) 20 | $detailedHelp = (New-Object -TypeName System.Windows.Forms.TextBox) 21 | $tabPage3 = (New-Object -TypeName System.Windows.Forms.TabPage) 22 | $examplesBox = (New-Object -TypeName System.Windows.Forms.TextBox) 23 | $tabControl1.SuspendLayout() 24 | $tabPage1.SuspendLayout() 25 | $tabPage2.SuspendLayout() 26 | $tabPage3.SuspendLayout() 27 | $MainForm.SuspendLayout() 28 | # 29 | #commandsList 30 | # 31 | $commandsList.FormattingEnabled = $true 32 | $commandsList.HorizontalScrollbar = $true 33 | $commandsList.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]13)) 34 | $commandsList.Name = 'commandsList' 35 | $commandsList.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]201,[System.Int32]550)) 36 | $commandsList.TabIndex = [System.Int32]0 37 | $commandsList.add_SelectedIndexChanged($commandsList_SelectedIndexChanged) 38 | # 39 | #helpBox 40 | # 41 | $helpBox.AcceptsReturn = $true 42 | $helpBox.AcceptsTab = $true 43 | $helpBox.BackColor = [System.Drawing.SystemColors]::Window 44 | $helpBox.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 45 | $helpBox.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]6,[System.Int32]6)) 46 | $helpBox.Multiline = $true 47 | $helpBox.Name = 'helpBox' 48 | $helpBox.ReadOnly = $true 49 | $helpBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 50 | $helpBox.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]876,[System.Int32]514)) 51 | $helpBox.TabIndex = [System.Int32]1 52 | $helpBox.WordWrap = $false 53 | # 54 | #tabControl1 55 | # 56 | $tabControl1.Controls.Add($tabPage1) 57 | $tabControl1.Controls.Add($tabPage2) 58 | $tabControl1.Controls.Add($tabPage3) 59 | $tabControl1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]221,[System.Int32]13)) 60 | $tabControl1.Name = 'tabControl1' 61 | $tabControl1.SelectedIndex = [System.Int32]0 62 | $tabControl1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]893,[System.Int32]549)) 63 | $tabControl1.TabIndex = [System.Int32]2 64 | # 65 | #tabPage1 66 | # 67 | $tabPage1.Controls.Add($helpBox) 68 | $tabPage1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 69 | $tabPage1.Name = 'tabPage1' 70 | $tabPage1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]885,[System.Int32]523)) 71 | $tabPage1.TabIndex = [System.Int32]0 72 | $tabPage1.Text = 'Main' 73 | $tabPage1.UseVisualStyleBackColor = $true 74 | # 75 | #tabPage2 76 | # 77 | $tabPage2.Controls.Add($detailedHelp) 78 | $tabPage2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 79 | $tabPage2.Name = 'tabPage2' 80 | $tabPage2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]885,[System.Int32]523)) 81 | $tabPage2.TabIndex = [System.Int32]1 82 | $tabPage2.Text = 'Detailed' 83 | $tabPage2.UseVisualStyleBackColor = $true 84 | # 85 | #detailedHelp 86 | # 87 | $detailedHelp.BackColor = [System.Drawing.SystemColors]::Window 88 | $detailedHelp.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 89 | $detailedHelp.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]7,[System.Int32]7)) 90 | $detailedHelp.Multiline = $true 91 | $detailedHelp.Name = 'detailedHelp' 92 | $detailedHelp.ReadOnly = $true 93 | $detailedHelp.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 94 | $detailedHelp.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]875,[System.Int32]513)) 95 | $detailedHelp.TabIndex = [System.Int32]0 96 | $detailedHelp.WordWrap = $false 97 | # 98 | #tabPage3 99 | # 100 | $tabPage3.Controls.Add($examplesBox) 101 | $tabPage3.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 102 | $tabPage3.Name = 'tabPage3' 103 | $tabPage3.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]885,[System.Int32]523)) 104 | $tabPage3.TabIndex = [System.Int32]2 105 | $tabPage3.Text = 'Examples' 106 | $tabPage3.UseVisualStyleBackColor = $true 107 | # 108 | #examplesBox 109 | # 110 | $examplesBox.BackColor = [System.Drawing.SystemColors]::Window 111 | $examplesBox.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 112 | $examplesBox.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]4)) 113 | $examplesBox.Multiline = $true 114 | $examplesBox.Name = 'examplesBox' 115 | $examplesBox.ReadOnly = $true 116 | $examplesBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 117 | $examplesBox.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]878,[System.Int32]516)) 118 | $examplesBox.TabIndex = [System.Int32]0 119 | $examplesBox.WordWrap = $false 120 | # 121 | #MainForm 122 | # 123 | $MainForm.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1126,[System.Int32]574)) 124 | $MainForm.Controls.Add($tabControl1) 125 | $MainForm.Controls.Add($commandsList) 126 | $MainForm.Name = 'MainForm' 127 | $MainForm.Text = 'Powershell Help' 128 | $MainForm.add_Load($MainForm_Load) 129 | $tabControl1.ResumeLayout($false) 130 | $tabPage1.ResumeLayout($false) 131 | $tabPage1.PerformLayout() 132 | $tabPage2.ResumeLayout($false) 133 | $tabPage2.PerformLayout() 134 | $tabPage3.ResumeLayout($false) 135 | $tabPage3.PerformLayout() 136 | $MainForm.ResumeLayout($false) 137 | Add-Member -InputObject $MainForm -Name base -Value $base -MemberType NoteProperty 138 | Add-Member -InputObject $MainForm -Name commandsList -Value $commandsList -MemberType NoteProperty 139 | Add-Member -InputObject $MainForm -Name helpBox -Value $helpBox -MemberType NoteProperty 140 | Add-Member -InputObject $MainForm -Name tabControl1 -Value $tabControl1 -MemberType NoteProperty 141 | Add-Member -InputObject $MainForm -Name tabPage1 -Value $tabPage1 -MemberType NoteProperty 142 | Add-Member -InputObject $MainForm -Name tabPage2 -Value $tabPage2 -MemberType NoteProperty 143 | Add-Member -InputObject $MainForm -Name detailedHelp -Value $detailedHelp -MemberType NoteProperty 144 | Add-Member -InputObject $MainForm -Name tabPage3 -Value $tabPage3 -MemberType NoteProperty 145 | Add-Member -InputObject $MainForm -Name examplesBox -Value $examplesBox -MemberType NoteProperty 146 | Add-Member -InputObject $MainForm -Name button1 -Value $button1 -MemberType NoteProperty 147 | } 148 | . InitializeComponent 149 | -------------------------------------------------------------------------------- /Powershell-Cmdlet-Explorer/Powershell-Cmdlet-Explorer.designer.ps1: -------------------------------------------------------------------------------- 1 | [void][System.Reflection.Assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') 2 | [void][System.Reflection.Assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') 3 | $MainForm = New-Object -TypeName System.Windows.Forms.Form 4 | [System.Windows.Forms.ListBox]$modulesList = $null 5 | [System.Windows.Forms.ListBox]$cmdletsList = $null 6 | [System.Windows.Forms.TabControl]$tabControl1 = $null 7 | [System.Windows.Forms.TabPage]$tabPage1 = $null 8 | [System.Windows.Forms.TextBox]$helpBox = $null 9 | [System.Windows.Forms.TabPage]$tabPage2 = $null 10 | [System.Windows.Forms.TextBox]$detailedHelp = $null 11 | [System.Windows.Forms.TabPage]$tabPage3 = $null 12 | [System.Windows.Forms.TextBox]$examplesBox = $null 13 | [System.Windows.Forms.Button]$button1 = $null 14 | function InitializeComponent 15 | { 16 | [System.Resources.ResXResourceReader]$resources = New-Object -TypeName System.Resources.ResXResourceReader -ArgumentList "$PSScriptRoot\Powershell-Cmdlet-Explorer.resx" 17 | $modulesList = (New-Object -TypeName System.Windows.Forms.ListBox) 18 | $cmdletsList = (New-Object -TypeName System.Windows.Forms.ListBox) 19 | $tabControl1 = (New-Object -TypeName System.Windows.Forms.TabControl) 20 | $tabPage1 = (New-Object -TypeName System.Windows.Forms.TabPage) 21 | $helpBox = (New-Object -TypeName System.Windows.Forms.TextBox) 22 | $tabPage2 = (New-Object -TypeName System.Windows.Forms.TabPage) 23 | $detailedHelp = (New-Object -TypeName System.Windows.Forms.TextBox) 24 | $tabPage3 = (New-Object -TypeName System.Windows.Forms.TabPage) 25 | $examplesBox = (New-Object -TypeName System.Windows.Forms.TextBox) 26 | $tabControl1.SuspendLayout() 27 | $tabPage1.SuspendLayout() 28 | $tabPage2.SuspendLayout() 29 | $tabPage3.SuspendLayout() 30 | $MainForm.SuspendLayout() 31 | # 32 | #modulesList 33 | # 34 | $modulesList.FormattingEnabled = $true 35 | $modulesList.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]13)) 36 | $modulesList.Name = 'modulesList' 37 | $modulesList.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]199,[System.Int32]589)) 38 | $modulesList.TabIndex = [System.Int32]0 39 | $modulesList.add_SelectedIndexChanged($modulesList_SelectedIndexChanged) 40 | # 41 | #cmdletsList 42 | # 43 | $cmdletsList.FormattingEnabled = $true 44 | $cmdletsList.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]218,[System.Int32]13)) 45 | $cmdletsList.Name = 'cmdletsList' 46 | $cmdletsList.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]237,[System.Int32]589)) 47 | $cmdletsList.TabIndex = [System.Int32]1 48 | $cmdletsList.add_SelectedIndexChanged($cmdletsList_SelectedIndexChanged) 49 | # 50 | #tabControl1 51 | # 52 | $tabControl1.Controls.Add($tabPage1) 53 | $tabControl1.Controls.Add($tabPage2) 54 | $tabControl1.Controls.Add($tabPage3) 55 | $tabControl1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]461,[System.Int32]12)) 56 | $tabControl1.Name = 'tabControl1' 57 | $tabControl1.SelectedIndex = [System.Int32]0 58 | $tabControl1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]857,[System.Int32]590)) 59 | $tabControl1.TabIndex = [System.Int32]3 60 | # 61 | #tabPage1 62 | # 63 | $tabPage1.Controls.Add($helpBox) 64 | $tabPage1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 65 | $tabPage1.Name = 'tabPage1' 66 | $tabPage1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]849,[System.Int32]564)) 67 | $tabPage1.TabIndex = [System.Int32]0 68 | $tabPage1.Text = 'Main' 69 | $tabPage1.UseVisualStyleBackColor = $true 70 | # 71 | #helpBox 72 | # 73 | $helpBox.AcceptsReturn = $true 74 | $helpBox.AcceptsTab = $true 75 | $helpBox.BackColor = [System.Drawing.SystemColors]::Window 76 | $helpBox.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 77 | $helpBox.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]3,[System.Int32]5)) 78 | $helpBox.Multiline = $true 79 | $helpBox.Name = 'helpBox' 80 | $helpBox.ReadOnly = $true 81 | $helpBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 82 | $helpBox.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]843,[System.Int32]559)) 83 | $helpBox.TabIndex = [System.Int32]1 84 | $helpBox.WordWrap = $false 85 | # 86 | #tabPage2 87 | # 88 | $tabPage2.Controls.Add($detailedHelp) 89 | $tabPage2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 90 | $tabPage2.Name = 'tabPage2' 91 | $tabPage2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]849,[System.Int32]564)) 92 | $tabPage2.TabIndex = [System.Int32]1 93 | $tabPage2.Text = 'Detailed' 94 | $tabPage2.UseVisualStyleBackColor = $true 95 | # 96 | #detailedHelp 97 | # 98 | $detailedHelp.BackColor = [System.Drawing.SystemColors]::Window 99 | $detailedHelp.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 100 | $detailedHelp.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]7,[System.Int32]7)) 101 | $detailedHelp.Multiline = $true 102 | $detailedHelp.Name = 'detailedHelp' 103 | $detailedHelp.ReadOnly = $true 104 | $detailedHelp.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 105 | $detailedHelp.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]839,[System.Int32]554)) 106 | $detailedHelp.TabIndex = [System.Int32]0 107 | $detailedHelp.WordWrap = $false 108 | # 109 | #tabPage3 110 | # 111 | $tabPage3.Controls.Add($examplesBox) 112 | $tabPage3.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]22)) 113 | $tabPage3.Name = 'tabPage3' 114 | $tabPage3.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]849,[System.Int32]564)) 115 | $tabPage3.TabIndex = [System.Int32]2 116 | $tabPage3.Text = 'Examples' 117 | $tabPage3.UseVisualStyleBackColor = $true 118 | # 119 | #examplesBox 120 | # 121 | $examplesBox.BackColor = [System.Drawing.SystemColors]::Window 122 | $examplesBox.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @('Lucida Console',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) 123 | $examplesBox.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]4,[System.Int32]4)) 124 | $examplesBox.Multiline = $true 125 | $examplesBox.Name = 'examplesBox' 126 | $examplesBox.ReadOnly = $true 127 | $examplesBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Both 128 | $examplesBox.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]842,[System.Int32]557)) 129 | $examplesBox.TabIndex = [System.Int32]0 130 | $examplesBox.WordWrap = $false 131 | # 132 | #MainForm 133 | # 134 | $MainForm.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1330,[System.Int32]616)) 135 | $MainForm.Controls.Add($tabControl1) 136 | $MainForm.Controls.Add($cmdletsList) 137 | $MainForm.Controls.Add($modulesList) 138 | $MainForm.Icon = ([System.Drawing.Icon]($resources.GetEnumerator() | Where-Object 'Key' -eq '$this.Icon').Value) 139 | $MainForm.Name = 'MainForm' 140 | $MainForm.Text = 'PowerShell Cmdlet Explorer' 141 | $MainForm.add_Load($MainForm_Load) 142 | $tabControl1.ResumeLayout($false) 143 | $tabPage1.ResumeLayout($false) 144 | $tabPage1.PerformLayout() 145 | $tabPage2.ResumeLayout($false) 146 | $tabPage2.PerformLayout() 147 | $tabPage3.ResumeLayout($false) 148 | $tabPage3.PerformLayout() 149 | $MainForm.ResumeLayout($false) 150 | Add-Member -InputObject $MainForm -Name base -Value $base -MemberType NoteProperty 151 | Add-Member -InputObject $MainForm -Name modulesList -Value $modulesList -MemberType NoteProperty 152 | Add-Member -InputObject $MainForm -Name cmdletsList -Value $cmdletsList -MemberType NoteProperty 153 | Add-Member -InputObject $MainForm -Name tabControl1 -Value $tabControl1 -MemberType NoteProperty 154 | Add-Member -InputObject $MainForm -Name tabPage1 -Value $tabPage1 -MemberType NoteProperty 155 | Add-Member -InputObject $MainForm -Name helpBox -Value $helpBox -MemberType NoteProperty 156 | Add-Member -InputObject $MainForm -Name tabPage2 -Value $tabPage2 -MemberType NoteProperty 157 | Add-Member -InputObject $MainForm -Name detailedHelp -Value $detailedHelp -MemberType NoteProperty 158 | Add-Member -InputObject $MainForm -Name tabPage3 -Value $tabPage3 -MemberType NoteProperty 159 | Add-Member -InputObject $MainForm -Name examplesBox -Value $examplesBox -MemberType NoteProperty 160 | Add-Member -InputObject $MainForm -Name button1 -Value $button1 -MemberType NoteProperty 161 | } 162 | . InitializeComponent 163 | -------------------------------------------------------------------------------- /Report-Functions.ps1: -------------------------------------------------------------------------------- 1 | $style = @" 2 | 33 | "@ 34 | 35 | function Generate-ADUserPasswordReport() { 36 | [cmdletBinding()] 37 | param( 38 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 39 | [System.String]$FileName, 40 | [parameter(Mandatory=$false)] 41 | [Management.Automation.PSCredential] $Credential 42 | ) 43 | 44 | process { 45 | if ($Credential -ne $null) { 46 | $users = Get-ADUser -Filter * -Credential $Credential -Properties "UserPrincipalName","SamAccountName","DisplayName","LastLogonDate","PasswordLastSet","LastBadPasswordAttempt","PasswordNeverExpires","LockedOut","PasswordExpired","PasswordNotRequired","BadLogonCount","badPwdCount","CannotChangePassword","logonCount" | Select-Object * -ExcludeProperty DistinguishedName,GivenName,ModifiedProperties,PropertyCount,RemovedProperties,AddedProperties,PropertyNames,Surname,SID,ObjectGUID,ObjectClass 47 | } else { 48 | $users = Get-ADUser -Filter * -Properties "UserPrincipalName","SamAccountName","DisplayName","LastLogonDate","PasswordLastSet","LastBadPasswordAttempt","PasswordNeverExpires","LockedOut","PasswordExpired","PasswordNotRequired","BadLogonCount","badPwdCount","CannotChangePassword","logonCount" | Select-Object * -ExcludeProperty DistinguishedName,GivenName,ModifiedProperties,PropertyCount,RemovedProperties,AddedProperties,PropertyNames,Surname,SID,ObjectGUID,ObjectClass 49 | } 50 | 51 | $usersHtml = $users | Select-Object * | ConvertTo-Html -Fragment -PreContent "

Active Directory Users - Password Information

" 52 | 53 | $title = "AD Users - Password Information" 54 | 55 | ConvertTo-Html -Head "$title$style" -Body "$searchbar$usersHtml" | Out-File $FileName 56 | 57 | } 58 | } 59 | 60 | function Generate-ADUserReport() { 61 | [cmdletBinding()] 62 | param( 63 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 64 | [System.String]$FileName, 65 | [parameter(Mandatory=$false)] 66 | [Management.Automation.PSCredential] $Credential 67 | ) 68 | 69 | process { 70 | if ($Credential -ne $null) { 71 | $users = Get-ADUser -Filter * -Credential $Credential -Properties "UserPrincipalName","SamAccountName","DisplayName","EmailAddress","Title","BadLogonCount","badPwdCount","CannotChangePassword","CanonicalName","Company","Country","Created","Department","Description","Enabled","GivenName","HomeDirectory","HomePhone","LastBadPasswordAttempt","LastLogonDate","LockedOut","logonCount","mail","Manager","Modified","Name","Office","OfficePhone","PasswordExpired","PasswordNeverExpires","PasswordNotRequired","primaryGroupID","ProtectedFromAccidentalDeletion","PasswordLastSet" | Select-Object * -ExcludeProperty ModifiedProperties,PropertyCount,RemovedProperties,AddedProperties,PropertyNames,ObjectClass 72 | } else { 73 | $users = Get-ADUser -Filter * -Properties "UserPrincipalName","SamAccountName","DisplayName","EmailAddress","Title","BadLogonCount","badPwdCount","CannotChangePassword","CanonicalName","Company","Country","Created","Department","Description","Enabled","GivenName","HomeDirectory","HomePhone","LastBadPasswordAttempt","LastLogonDate","LockedOut","logonCount","mail","Manager","Modified","Name","Office","OfficePhone","PasswordExpired","PasswordNeverExpires","PasswordNotRequired","primaryGroupID","ProtectedFromAccidentalDeletion","PasswordLastSet" | Select-Object * -ExcludeProperty ModifiedProperties,PropertyCount,RemovedProperties,AddedProperties,PropertyNames,ObjectClass 74 | } 75 | 76 | $usersHtml = $users | Select-Object * | ConvertTo-Html -Fragment -PreContent "

Active Directory Users

" 77 | 78 | $title = "AD Users" 79 | 80 | ConvertTo-Html -Head "$title$style" -Body "$searchbar$usersHtml" | Out-File $FileName 81 | 82 | } 83 | } 84 | 85 | function Generate-ADGroupReport() { 86 | [cmdletBinding()] 87 | param( 88 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 89 | [System.String]$FileName, 90 | [parameter(Mandatory=$false)] 91 | [Management.Automation.PSCredential] $Credential 92 | ) 93 | 94 | process { 95 | if ($Credential -ne $null) { 96 | $groups = Get-ADGroup -Filter * -Credential $Credential 97 | } else { 98 | $groups = Get-ADGroup -Filter * 99 | } 100 | 101 | $groupsHtml = $groups | Select-Object Name,GroupCategory,GroupScope | ConvertTo-Html -Fragment -PreContent "

Active Directory Groups

" 102 | 103 | $title = "AD Groups" 104 | 105 | ConvertTo-Html -Head "$title$style" -Body "$searchbar$groupsHtml" | Out-File $FileName 106 | } 107 | } 108 | 109 | ### Generate AD Computer Report ### 110 | function Generate-ADComputerReport() { 111 | [cmdletBinding()] 112 | param( 113 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 114 | [System.String]$FileName, 115 | [parameter(Mandatory=$false)] 116 | [Management.Automation.PSCredential] $Credential 117 | ) 118 | 119 | process { 120 | # Grab list of computers in Active Directory 121 | if ($Credential -ne $null) { 122 | $servers = Get-ADComputer -Filter * -Credential $Credential 123 | } else { 124 | $servers = Get-ADComputer -Filter * 125 | } 126 | # Convert list to HTML 127 | $serversHtml = $servers | Select-Object DNSHostName,Enabled,Name,ObjectClass,ObjectGUID,SamAccountName | ConvertTo-Html -Fragment -PreContent "

Active Directory Computers

" 128 | 129 | # Create HTML file 130 | $title = "AD Computer List" 131 | 132 | # Convert everything to HTML and output to file 133 | ConvertTo-Html -Head "$title$style" -Body "$searchbar$serversHtml" | Out-File $FileName 134 | } 135 | } 136 | 137 | ### Generate AD Computer Network Report ### 138 | function Generate-ADComputerNetworkReport() { 139 | [cmdletBinding()] 140 | param( 141 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 142 | [System.String]$FileName, 143 | [parameter(Mandatory=$false)] 144 | [Management.Automation.PSCredential] $Credential 145 | ) 146 | 147 | process { 148 | # Grab list of computers in Active Directory 149 | if ($Credential -ne $null) { 150 | $servers = Get-ADComputer -Filter * -Credential $Credential 151 | } else { 152 | $servers = Get-ADComputer -Filter * 153 | } 154 | $serversNet = @() 155 | 156 | foreach ($server in $servers) { 157 | Write-Host "Testing "$server.DNSHostName 158 | $results = Test-Server -ComputerName $server.DNSHostName 159 | $serversNet += $results 160 | } 161 | 162 | $serversHtml = $serversNet | ConvertTo-Html -Fragment -PreContent "

AD Computers - Network Status

" 163 | 164 | # Create HTML file 165 | 166 | $title = "AD Computer List - Network" 167 | 168 | # Convert everything to HTML and output to file 169 | ConvertTo-Html -Head "$title$style" -Body "$searchbar$serversHtml" | Out-File $FileName 170 | } 171 | } 172 | 173 | # This is not my original work, I downloaded it to use with GetFailed.ps1 174 | Function Test-Server{ 175 | [cmdletBinding()] 176 | param( 177 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 178 | [string[]]$ComputerName, 179 | [parameter(Mandatory=$false)] 180 | [switch]$CredSSP, 181 | [Management.Automation.PSCredential] $Credential) 182 | 183 | begin{ 184 | $total = Get-Date 185 | $results = @() 186 | if($credssp){if(!($credential)){Write-Host "must supply Credentials with CredSSP test";break}} 187 | } 188 | process{ 189 | foreach($name in $computername) 190 | { 191 | $dt = $cdt= Get-Date 192 | Write-verbose "Testing: $Name" 193 | $failed = 0 194 | try{ 195 | $DNSEntity = [Net.Dns]::GetHostEntry($name) 196 | $domain = ($DNSEntity.hostname).replace("$name.","") 197 | $ips = $DNSEntity.AddressList | %{$_.IPAddressToString} 198 | } 199 | catch 200 | { 201 | $rst = "" | select Name,IP,Domain,Ping,WSMAN,CredSSP,RemoteReg,RPC,RDP 202 | $rst.name = $name 203 | $results += $rst 204 | $failed = 1 205 | } 206 | Write-verbose "DNS: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 207 | if($failed -eq 0){ 208 | foreach($ip in $ips) 209 | { 210 | 211 | $rst = "" | select Name,IP,Domain,Ping,WSMAN,CredSSP,RemoteReg,RPC,RDP 212 | $rst.name = $name 213 | $rst.ip = $ip 214 | $rst.domain = $domain 215 | ####RDP Check (firewall may block rest so do before ping 216 | try{ 217 | $socket = New-Object Net.Sockets.TcpClient($name, 3389) 218 | if($socket -eq $null) 219 | { 220 | $rst.RDP = $false 221 | } 222 | else 223 | { 224 | $rst.RDP = $true 225 | $socket.close() 226 | } 227 | } 228 | catch 229 | { 230 | $rst.RDP = $false 231 | } 232 | Write-verbose "RDP: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 233 | #########ping 234 | if(test-connection $ip -count 1 -Quiet) 235 | { 236 | Write-verbose "PING: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 237 | $rst.ping = $true 238 | try{############wsman 239 | Test-WSMan $ip | Out-Null 240 | $rst.WSMAN = $true 241 | } 242 | catch 243 | {$rst.WSMAN = $false} 244 | Write-verbose "WSMAN: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 245 | if($rst.WSMAN -and $credssp) ########### credssp 246 | { 247 | try{ 248 | Test-WSMan $ip -Authentication Credssp -Credential $cred 249 | $rst.CredSSP = $true 250 | } 251 | catch 252 | {$rst.CredSSP = $false} 253 | Write-verbose "CredSSP: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 254 | } 255 | try ########remote reg 256 | { 257 | [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $ip) | Out-Null 258 | $rst.remotereg = $true 259 | } 260 | catch 261 | {$rst.remotereg = $false} 262 | Write-verbose "remote reg: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 263 | try ######### wmi 264 | { 265 | $w = [wmi] '' 266 | $w.psbase.options.timeout = 15000000 267 | $w.path = "\\$Name\root\cimv2:Win32_ComputerSystem.Name='$Name'" 268 | $w | select none | Out-Null 269 | $rst.RPC = $true 270 | } 271 | catch 272 | {$rst.rpc = $false} 273 | Write-verbose "WMI: $((New-TimeSpan $dt ($dt = get-date)).totalseconds)" 274 | } 275 | else 276 | { 277 | $rst.ping = $false 278 | $rst.wsman = $false 279 | $rst.credssp = $false 280 | $rst.remotereg = $false 281 | $rst.rpc = $false 282 | } 283 | $results += $rst 284 | }} 285 | Write-Verbose "Time for $($Name): $((New-TimeSpan $cdt ($dt)).totalseconds)" 286 | Write-Verbose "----------------------------" 287 | } 288 | } 289 | end{ 290 | Write-Verbose "Time for all: $((New-TimeSpan $total ($dt)).totalseconds)" 291 | Write-Verbose "----------------------------" 292 | return $results 293 | } 294 | } --------------------------------------------------------------------------------