<# This code is used for updating the data used by Pester Tests if device, tickets data in core changes or you want to change the tickets/devices to test. Updates the PSO used in the tests from live data as devices can be decommed and tickets can be achived. Run a version of PoshCore that you know is working e.g. the previouse version to generate this data using the commands below The pso used in the tests will be generated and added to clipboard which you can then update the PSO in the test #> #copy this function into a powershell window and run the commands below depending on which test you want to update. Function Get-PSOLiveData ($Result,$number) { $Names = $Result | get-member -membertype NoteProperty -ErrorAction SilentlyContinue | select name [String[]]$psostring = $null $psostring += "`$ComputerPSO$number = New-Object PSObject -Property @{" ForEach($name in $names) { #Add data if it has a value a value, length less than 100, excludes passwords as these will more likely to be rotated/changed $HasData = ($($result."$($name.name)") | measure-Object).count If ($HasData -gt 0 -and ($result."$($name.name)").length -lt 100 -and $($result."$($name.name)") -ne '' -and $($name.name) -notlike "*password*") { $psostring += "$($name.name) = '$($result."$($name.name)")'" } } $psostring += "}" return $psostring } #################### Generate PSO for PoshCore-Computer.Tests - BEGIN #################### #region #For PoshCore-Computer.Tests #An example of the PSO output is at the bottom of this script. #device 560559 $Device = "560559" $Result = Find-CoreComputer -Computers @($Device) -Attributes @("Default","Network","Drac","Bandwidth","Attached","Backup","Storage","Misc","Domain","Implementation","Is","Os","Password","Skus") $TestPSO1 = Get-PSOLiveData -Result $Result -number 1 $TestPSO1 | Clip; Write-Host "PSO added to clipboard for device $Device" #device 560570 $Device = "560570" $Result = Find-CoreComputer -Computers @($Device) -Attributes @("Default","Network","Drac","Bandwidth","Attached","Backup","Storage","Misc","Domain","Implementation","Is","Os","Password","Skus") $TestPSO2 = Get-PSOLiveData -Result $Result -number 2 $TestPSO2 | Clip; Write-Host "PSO added to clipboard for device $Device" <# Example of output e.g. a pSO with the retruned data. $ComputerPSO1 = New-Object PSObject -Property @{ account_id = '1103359' account_name = 'International Enterprise Support Test Account' add_userid_to_domain = 'True' am_queue = 'Account Management - Intensive' attached_devices = '560591' attached_firewalls = '407882' attached_san_or_das = '560591' bw_poller = 'bw1.lon1.core.rackspace.com' bw_subscription = '0' contract = '87732' created = '2014-01-02 11:05:14' datacenter_symbol = 'LON3' date_contract_received = '2014-01-03 03:40:39' date_online = '2014-01-14 10:35:40' domain_name = 'lon.intensive.int' drac_ips = '10.8.113.157' drac_usernames = 'root' due_date = '2016-04-19 03:40:39' due_to_support_date = '2016-04-19 03:40:39' exnet_zone = 'ExNet-331' has_been_online = 'True' has_drac = 'True' ip_addresses = '10.136.132.235 134.213.21.4' is_behind_net_device = 'True' is_ice_complete = 'True' is_online = 'True' is_server = 'True' is_uk_account = 'True' is_windows = 'True' location = 'XB7-1E[20] (AggExNet)' name = '560570-DB2.rackspace.com' nickname = 'DB2' number = '560570' os = 'DELL PowerEdge R720 Windows' os_name = 'Windows 2012 R2 Standard - 64 bit' os_type = 'Microsoft Windows' platform_model = 'DELL PowerEdge R720 Windows Required' platform_name = 'DELL PowerEdge R720 Windows' platform_type = 'Server' pre_build_message = 'Master ticket: 160404-03914' primary_dns = '83.138.151.80' primary_ip = '134.213.21.4' primary_userid = 'swaller' rack_rotation_cycle_number = '3' rba_login_method = 'Password Auth' segment = 'Intensive' segment_queue = 'Intensive (All Teams)' service_level_name = 'Intensive' Skus = ' ' status_name = 'Online/Complete' support_level = 'Fanatical Support Plus' type = 'DELL PowerEdge R720 Windows' usage_type = 'Files' vm_info = '404 ' } #> #endregion ##################### Generate PSO for PoshCore-Computer.Tests - END ##################### #################### Generate PSO for PoshCore-Contact.Tests - BEGIN #################### #region #user mark4808 (mark wichall) $username = "mark4808" $Result = Find-CoreContact -Ssos "$username" -CustomAttribute @{"reverse_name"="reverse_name"} $TestPSO1user = Get-PSOLiveData -Result $Result -number 1 $TestPSO1user | Clip; Write-Host "PSO added to clipboard for device $username" #user mart6771 (martin howlett) $username = "mart6141" $Result = Find-CoreContact -Ssos "$username" -CustomAttribute @{"reverse_name"="reverse_name"} $TestPSO2user = Get-PSOLiveData -Result $Result -number 2 $TestPSO2user | Clip; Write-Host "PSO added to clipboard for device $username" #endregion ##################### Generate PSO for PoshCore-Contact.Tests - END ##################### #################### Generate PSO for PoshCore-Ticket.Tests - BEGIN #################### #region #NA - A ticket is generated during the process of running the pester test pre-creation is not applicable. #endregion ##################### Generate PSO for PoshCore-Ticket.Tests - END ##################### #################### Generate PSO for PoshCore-Account.Tests - BEGIN #################### #region <# N/A - Account data is highly structured when AccountTeam attributes are included, therefore we use JSON. Code to regenerate is in the comments of the relevant pester script #> #endregion ##################### Generate PSO for PoshCore-Account.Tests - END #####################