# Load the hotel configuration $hotelConfig = Get-Content -Path "HotelConfig.json" | ConvertFrom-Json # Endpoint and SOAP action $endpoint = "$($hotelConfig.SiteURL)/ResvAdvanced" $soapAction = "http://webservices.micros.com/og/4.3/ResvAdvanced/FetchRoomStatusRequest" # Bypass SSL certificate validation (use with caution) [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } # Set the current time in UTC for timestamps $currentTime = [DateTime]::UtcNow $createdTime = $currentTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ") $expiresTime = $currentTime.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Define the SOAP request body with dynamic hotel data $xmlContent = @" $createdTime $expiresTime $($hotelConfig.UserName) $($hotelConfig.Password) $($hotelConfig.SiteUsername) $($hotelConfig.Domain) "@ # Define the headers $headers = @{ "Content-Type" = "text/xml; charset=utf-8" "SOAPAction" = $soapAction } $byteArray = [System.Text.Encoding]::UTF8.GetBytes($xmlContent) # Send the request with verbose output $response = Invoke-WebRequest -Uri $endpoint -Method Post -Body $byteArray -Headers $headers -UseBasicParsing -Verbose # Output the response $response.Content # Parse the XML content for namespaces [xml]$xmlResponse = $response.Content $namespaceManager = New-Object System.Xml.XmlNamespaceManager($xmlResponse.NameTable) $namespaceManager.AddNamespace("res", "http://webservices.micros.com/og/4.3/ResvAdvanced/") # Select nodes with the namespace prefix $roomNodes = $xmlResponse.SelectNodes("//res:RoomStatus", $namespaceManager) # Collect room data $roomData = @() foreach ($room in $roomNodes) { $roomID = $room.RoomNumber $roomType = $room.RoomType $roomDescription = $room.RoomDescription $roomData += [PSCustomObject]@{ RoomID = $roomID RoomType = $roomType RoomDescription = $roomDescription } } # Export to CSV $roomData | Export-Csv -Path "RoomStatusReport.csv" -NoTypeInformation -Encoding UTF8 Write-Output "Room status data has been saved to RoomStatusReport.csv"