Skip to content

Instantly share code, notes, and snippets.

@mattman-ps
Created March 22, 2024 15:24
Show Gist options
  • Save mattman-ps/abe90162acbb6b36992cd4b5062c7e45 to your computer and use it in GitHub Desktop.
Save mattman-ps/abe90162acbb6b36992cd4b5062c7e45 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment