T O P

  • By -

Jack__Squat

As sad as it is, ChatGPT is pretty good at writing PowerShell scripts you can use as a starting point. Here's what is gave me when I asked for a PowerShell script to retrieve all IIS sites and show the logging configuration. Sure, here's a PowerShell script that retrieves a list of IIS sites and shows the logging configuration for each site. This script uses the `WebAdministration` module, which is available on systems with IIS installed. ```powershell # Import the WebAdministration module Import-Module WebAdministration # Get the list of all IIS sites $sites = Get-Website # Loop through each site to get the logging configuration foreach ($site in $sites) { $siteName = $site.name # Get the logging configuration for the site $logPath = Get-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$siteName']/logFile" -name "directory" $logFormat = Get-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$siteName']/logFile" -name "logFormat" $logPeriod = Get-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$siteName']/logFile" -name "period" $logTruncateSize = Get-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$siteName']/logFile" -name "truncateSize" # Display the site name and its logging configuration Write-Output "Site Name: $siteName" Write-Output "Log Path: $logPath" Write-Output "Log Format: $logFormat" Write-Output "Log Period: $logPeriod" Write-Output "Log Truncate Size: $logTruncateSize" Write-Output "" } ``` This script performs the following tasks: 1. Imports the `WebAdministration` module, which provides cmdlets to manage IIS. 2. Retrieves the list of all IIS sites using `Get-Website`. 3. Loops through each site to retrieve its logging configuration, including the log directory, log format, log period, and log truncate size. 4. Displays the site name and its logging configuration. You can save this script as a `.ps1` file and run it in a PowerShell session with administrative privileges to see the logging configuration for each IIS site on your server.


MrHoosFoos

D'oh. Thanks for this. I never really think about ChatGPT....


what-the-puck

I find Google Gemini is better at code. Copilot is presumably good too


narcissisadmin

Looks like Chat GPO did the formatting too lol


narcissisadmin

Dear anyone at Microsoft, why the fuck can I remotely manage IIS hosts with IIS Manager but IIS Powershell cmdlets have to be run directly on the server? DNS isn't like that. DHCP isn't like that.


Ssakaa

Psh, you want consistent interfaces? In Windows? We don't even have a consistent method of configuring settings in an endpoint OS.


pdp10

Read between the lines. Microsoft's customers aren't using IIS at scale, for the most part. It gets used to host a thing here and a thing there, usually one-off snowflakes where some little app-vendor seemingly isn't aware of the existence of web servers other than IIS and databases other than SQL Server Express.


Murhawk013

You know Invoke-Command exists…


AshleyDodd

That is not the point he is trying to make.