# 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 Rflag = 0 RoomDescription = $roomDescription RoomTypeCode = $roomType TelNo1 = "" TelNo2 = "" } } # Export to CSV $roomData | Export-Csv -Path "RoomStatusReport.csv" -NoTypeInformation -Encoding UTF8 # The below parameter is used for version 7 of powershell for the above command # -UseQuotes never Write-Output "Room status data has been saved to RoomStatusReport.csv" # because we cannot remove the quote marks due to the powershell version, we use the below command to remove them (Get-Content .\RoomStatusReport.csv -Encoding UTF8) | % {$_ -replace '"',''} | Select-String -Pattern "^\d\d\d," | out-File .\RoomStatusReport.csv -Encoding utf8 Write-Output "removed Quotes" #adding the headers back in $header = 'RoomID,Rflag,RoomDescription,RoomTypeCode,TelNo1,TelNo2' $data = Get-Content .\RoomStatusReport.csv -Encoding UTF8 $header | Set-Content .\RoomStatusReport.csv -NoNewline $data | Add-Content .\RoomStatusReport.csv Write-Output "added headers back in"