Skip to content

Instantly share code, notes, and snippets.

View mattman-ps's full-sized avatar

MattMan mattman-ps

View GitHub Profile
@mattman-ps
mattman-ps / gist:abe90162acbb6b36992cd4b5062c7e45
Created March 22, 2024 15:24
Create a Website object that protects the password string on Get-WebSite
# I don't like passing a clear text password and it sounds like this will not be fixed anytime soon
# only an admin can run the WebAdministration module, but this could cause issues in some instances.
$IISSite = "mycoolsite"
Import-Module -Name WebAdministration
$SiteProperties = (Get-Website -Name $IISSite | Select-Object -Property *)
$SecurePassword = ConvertTo-SecureString -String $SiteProperties.password -AsPlainText -Force
$SiteProperties.password = $null
$SiteProperties | Add-Member -MemberType NoteProperty -Name "SecurePassword" -Value $SecurePassword
$SiteProperties | Format-List