Hi,
I am a beginner with powershell and PSU. I am trying to import all my scripts from PS to PSU and execute via a dashboard.
What I am trying to do is very basic, from the dashboard open & update a csv file via a button then excute the script via another button.
the script will import the updated csv file .
My issue is when clicking the button the csv file is not opening from the dashbord but works fine from powershell.
Any help would be appreciated.
Thanks
My script :
New-UDButton -Text ‘Update CSV File Before Executing the Script’ -OnClick {
Invoke-Item ‘E:\admin\hostlist.csv’
New-UDButton -Text ‘Click Here to Run The Script’ -OnClick {
Invoke-PSUScript ‘host.ps1’
What is the full context to this? Are you trying to add a line to the end of it? Are you trying to modify data that is in the CSV?
To me, this seems like you need to import the CSV, display it in a table that allows editing, have the user edit the data, then export it. It works when you run it from PowerShell because once you do invoke-Item it will open it in notepad or excel or whatever program is the default.
Hi,
I have several scripts which imports csv files after users update the variables before executing it.
CSV file is in a local share in PSU server.
Rather than going to that local share, open csv file and update, I would like to have a button to open the csv file from the dashboard so that the user can update and save.
If there is any possibilities to display directly that csv file in the dashboard and save or
have a table in the dashboard where user can add the details which will then update the csv and imported by the script would be great as well.
Thanks for the help.
Example of my script:
#### IMPORT CSV FILE ####
$idraclist = Import-Csv "E:\Scripts\Powershell-Universal-Scripts\iDRAC\idraclist.csv"
write-host "This script will reset root password, import idrac SCP and set new time zone"
sleep 2
# Enter existing credential
$pwd = $Secret:idracold
$newpass = $Secret:idracnew
write-host "Resetting iDRAC root password"
foreach ($item in $idraclist) {
# idrac list imported from CSV
$idracIP = $item.idracIP
$timezone = $item.timezone
$region = $item.region
# Reset root password
racadm -r $idracIP -u root -p $pwd set iDRAC.Users.2.Password $newpass
sleep 2
}
write-host "Root password is now changed on all hosts"
sleep 2
write-host "Configuring new Timezone"
foreach ($item in $idraclist) {
# idrac list imported from CSV
$idracIP = $item.idracIP
$timezone = $item.timezone
$region = $item.region
# Change timezone
racadm -r $idracIP -u root -p $newpass set iDRAC.TIME.Timezone $timezone
sleep 2
}
write-host "New Timezone is now configured on all hosts"
sleep 2
Write-Host "Importing" $region "iDRAC Server Configuration profile."
foreach ($item in $idraclist) {
# idrac list
$idracIP = $item.idracIP
$timezone = $item.timezone
$region = $item.region
# Import Server Configuration Profile XML
if ($region -eq "AMER") {
racadm -r $idracIP -u root -p $newpass set -t xml -f E:\iDRAC\scp-idrac-no-ip-AMER.xml
}
elseif ($region -eq "EMEA") {
racadm -r $idracIP -u root -p $newpass set -t xml -f E:\iDRAC\scp-idrac-no-ip-EMEA.xml
}
elseif ($region -eq "APAC") {
racadm -r $idracIP -u root -p $newpass set -t xml -f E:\iDRAC\scp-idrac-no-ip-APAC.xml
}
else
{
Write-Host 'Sorry, the region is not correct' }
}
write-host $region "iDRAC Server Configuration profile is now imported on all hosts"
I tried few things but seems that result is not as expected.
Do you have any examples which can be very helpful ? I have also added the scripts above for a better understanding.
Thanks
Please see the updates below. I’m opening a modal when you click the button that has the code editor in. It also has a save button that reads the contents of the code editor and writes them to disk.
# Use Get-UDPage -Name 'IDRAC' to use this page in your dashboard
$AppToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yM3IiLCJuYmYiOjE2NzYwMjI2ODMsImV4cCI6MjEzMzkzOTA2MCwiaXNzIjoiSXJvbm1hblNvZnR3YXJlIiwiYXVkIjoiUG93ZXJTaGVsbFVuaXZlcnNhbCJ9.57kslyhZSHGxEtAPldKKtKzGe_Bm1uvOLPap2dRrHY8'
$CSVPath = E:\Scripts\Powershell-Universal-Scripts\iDRAC\idraclist.csv
New-UDButton -Text 'HOME PAGE' -Style @{ Width = "150px"; Height = "50px"} -OnClick {
Invoke-UDRedirect -url http://psuserver:5000/scripts/Home
}
New-UDGrid -Item -SmallSize 6 -Content {
New-UDCard -Title 'IDRAC CONFIGURATION' -Content {
New-UDTypography -Variant h6 "This script will configure idracs of below listed hosts (IPs). Before executing, please update the CSV file and check if the details displayed in the table are correct."
}
}
New-UDDynamic -Content {
$Data = Import-Csv $CSVPath
New-UDTable -Data $Data
} -AutoRefresh -AutoRefreshInterval 5
New-UDButton -Text 'Click here to update CSV file before executing the script' -Style @{ Width = "400px"; Height = "50px"} -OnClick {
$CSV = Get-Content $CSVPath
Show-UDModal -Content {
New-UDCodeEditor -Id 'codeEditor' -Height 500 -Theme 'vs-dark' -Code $CSV
New-UDButton -Text 'Save' -OnClick {
Set-Content -Value ((Get-UDElement -Id 'codeEditor').Code) -Path $CSVPath
Hide-UDModal
}
}
}
New-UDButton -Text 'Click here to run the script' -Style @{ Width = "250px"; Height = "50px"} -OnClick {
Set-UDElement -Id 'button' -Properties @{
disabled = $true
text = "Running the script"
}
Connect-PSUServer -ComputerName http://localhost:5000 -AppToken $AppToken
$Job = Invoke-PSUScript -Script 'iDrac-Configuration.ps1'
while($Job.Status -ne 'Completed')
{
Start-Sleep 1
$Output = (Get-PSUJobOutput -Job $Job).Data -join ([Environment]::NewLine)
Set-UDElement -Id 'codeEditor' -Properties @{
code = $Output
}
$Job = Get-PSUJob -Id $Job.Id
}
Set-UDElement -Id 'button' -Properties @{
disabled = $false
text = "Click here to run the script"
}
} -Id 'button'
Hi @adam ,
Many thanks for your help. I am pretty much nearing to the result.
When I click the button, the code editor is empty (content from csv is not shown) and I have the below error.
First I’ll say I would recommend not leaking any Bastion/iDrac information (for the purposes of demonstration, I would create a “fake” set of IP’s, and for any API Keys just leave blank.
Second, you have tons of different options for editing the data. Here is some code for you to look at and refine .
My apologies if I missed anything obvious, I created a csv with only 3 columns on my local machine to do some testing with.
@Jori it’s really awesome and beyond my expectations and much better !!!
it’s really cool from you, I really appreciate the help received for a beginner in the world of scripting from you all and this forum.
Scripting with PS requires a certain mindset (to work through the flow of the script) and PSU only adds to that, with quirks of the product and dynamic elements vs non-dynamic.
You’ll need to add the -ShowPagination and ‘-PageSize X’ parameter. The first will show the page controls, the other will determine how many rows per page.
Hi @Jori ,
I am trying to add few extra functions with this code to prefill information of few table columns
When user click on edit button, I would like to have choices for user on region and timezone so that the user don’t need to enter data manually.
I tried to use filter funtion unsuccessfully, any help would be appreciated
Not sure if I’m understanding you correctly, but let me try.
Are you trying to have a button open up a modal window so they can select some settings, then have the Table use those previous selections when filtering data?
Hi @Jori
Yes, select pre filled information rather putting it manually
I would like to collect data from either powershell universal if there is any possibilities or vcenter for example server name, network nic, datastore etc…