<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: powershell script in ONTAP Discussions</title>
    <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457259#M44365</link>
    <description>&lt;P&gt;can you share the completed/fixed scripts. am also looking for health check scripts for bunch of clusters.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 08:58:12 GMT</pubDate>
    <dc:creator>manistorage</dc:creator>
    <dc:date>2024-12-10T08:58:12Z</dc:date>
    <item>
      <title>powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456861#M44296</link>
      <description>&lt;P&gt;I am recently learning powershell scripting, how can I write scripts to successfully access adv permissions,&lt;/P&gt;&lt;P&gt;I tried to pass y after set adv, but it didn't work, I don't know how to solve this problem, hope someone can help modify my script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;my script&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;# Set connection information&lt;BR /&gt;$ONTAPHost = Read-Host "Enter the IP address of the ONTAP cluster"&lt;BR /&gt;$User = Read-Host "Enter username"&lt;BR /&gt;$Password = Read-Host "Enter password"&lt;BR /&gt;$OutputFile = "commands_output.txt" # Output file path&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Import Posh-SSH module from removable drive, need to change the drive letter&lt;BR /&gt;Import-Module F:\Posh-SSH&lt;/P&gt;&lt;P&gt;# Create an SSH session and pass credentials&lt;BR /&gt;$securePassword = $Password | ConvertTo-SecureString -AsPlainText -Force&lt;BR /&gt;$credential = New-Object System.Management.Automation.PSCredential($User, $securePassword)&lt;/P&gt;&lt;P&gt;# Define command array&lt;BR /&gt;$commands = @(&lt;BR /&gt;"cluster show",&lt;BR /&gt;"set adv",&lt;BR /&gt;"system node image show"&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;# Try to connect to the ONTAP cluster&lt;BR /&gt;try {&lt;BR /&gt;# Creating an SSH Session&lt;BR /&gt;$session = New-SSHSession -ComputerName $ONTAPHost -Credential $credential -ErrorAction Stop&lt;BR /&gt;Write-Host "SSH session established successfully."&lt;/P&gt;&lt;P&gt;# If the file already exists, clear the file contents&lt;BR /&gt;if (Test-Path $OutputFile) {&lt;BR /&gt;Clear-Content -Path $OutputFile&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Loop through the array of commands and execute them in turn&lt;BR /&gt;foreach ($command in $commands) {&lt;BR /&gt;Write-Host "`nExecuting command: $command"&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;# Execute the current command and get the result&lt;BR /&gt;$result = Invoke-SSHCommand -SessionId $session.SessionId -Command $command -ErrorAction Stop&lt;/P&gt;&lt;P&gt;# Record the command execution to a file&lt;BR /&gt;Add-Content -Path $OutputFile -Value "`n::&amp;gt; $command"&lt;/P&gt;&lt;P&gt;# Output the result of the command&lt;BR /&gt;if ($result.Output) {&lt;BR /&gt;$result.Output -split "`n" | ForEach-Object {&lt;BR /&gt;Add-Content -Path $OutputFile -Value $_&lt;BR /&gt;}&lt;BR /&gt;} else {&lt;BR /&gt;Add-Content -Path $OutputFile -Value "No output received for '$command'."&lt;BR /&gt;}&lt;BR /&gt;} catch {&lt;BR /&gt;Write-Host "Error executing command: $command"&lt;BR /&gt;Add-Content -Path $OutputFile -Value "Error executing command: $command - $_"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;} catch {&lt;BR /&gt;Write-Host "Failed to establish SSH session or execute command: $_"&lt;BR /&gt;Add-Content -Path $OutputFile -Value "Failed to establish SSH session or execute command: $_"&lt;BR /&gt;exit&lt;BR /&gt;} finally {&lt;BR /&gt;# Make sure to close the SSH session at the end of the script&lt;BR /&gt;if ($session) {&lt;BR /&gt;Remove-SSHSession -SessionId $session.SessionId&lt;BR /&gt;Write-Host "SSH session closed."&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;outputfile&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;::&amp;gt; cluster show&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Last login time: 11/25/2024 16:21:20&lt;/P&gt;&lt;P&gt;Node Health Eligibility&lt;BR /&gt;--------------------- ------- ------------&lt;BR /&gt;FAS2720-01 true true&lt;BR /&gt;FAS2720-02 true true&lt;BR /&gt;2 entries were displayed.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;::&amp;gt; set adv&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Last login time: 11/25/2024 16:22:14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;::&amp;gt; system node image show&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Last login time: 11/25/2024 16:22:14&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Error: "image" is not a recognized command&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 08:39:13 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456861#M44296</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-11-25T08:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456883#M44297</link>
      <description>&lt;P&gt;$commands = "cluster show;set adv;system node image show;set adm"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Invoke-Ncssh -Command $commands&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NcController : cluster01&lt;BR /&gt;Value :&lt;BR /&gt;Last login time: 11/26/2024 01:49:19&lt;BR /&gt;Node Health Eligibility&lt;BR /&gt;--------------------- ------- ------------&lt;BR /&gt;node01a true true&lt;BR /&gt;node01b true true&lt;BR /&gt;2 entries were displayed.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Is&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Is&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Install&lt;BR /&gt;Node Image Default Current Version Date&lt;BR /&gt;-------- ------- ------- ------- ------------------------- -------------------&lt;BR /&gt;node01a&lt;BR /&gt;image1 false false 9.13.1P6 3/25/2024 11:52:38&lt;BR /&gt;image2 true true 9.13.1P7 6/7/2024 11:27:28&lt;BR /&gt;node01b&lt;BR /&gt;image1 false false 9.13.1P6 3/25/2024 11:53:24&lt;BR /&gt;image2 true true 9.13.1P7 6/7/2024 11:28:18&lt;BR /&gt;4 entries were displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;( my version of toolkit is 9.15.x so not Invoke-SSHCommand)&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 01:01:16 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456883#M44297</guid>
      <dc:creator>Sanaman</dc:creator>
      <dc:date>2024-11-26T01:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456885#M44299</link>
      <description>&lt;P&gt;hi sanaman&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, first of all, thank you for your reply. PSTK can indeed get the result I want,&amp;nbsp;so is it possible to Invoke-SSHCommand ?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 02:02:06 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456885#M44299</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-11-26T02:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456889#M44302</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm really laughing at myself for thinking so much, I just need to use the parameter -confirmations off after set adv.......... T_T&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Turn off confirmation&lt;/P&gt;&lt;P&gt;"set adv -c off"&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 06:55:43 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/456889#M44302</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-11-26T06:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457259#M44365</link>
      <description>&lt;P&gt;can you share the completed/fixed scripts. am also looking for health check scripts for bunch of clusters.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:58:12 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457259#M44365</guid>
      <dc:creator>manistorage</dc:creator>
      <dc:date>2024-12-10T08:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457269#M44369</link>
      <description>&lt;P&gt;You can put your commands into the command array, most likely it will run (I'm not sure about your environment), the script is fine because I was unable to execute the system node image show, other commands will run. This script is only used for log collection and does not have the function of health check. I need to check logs to determine whether there is a problem. I think the script may not be able to accurately identify the problem, and I'm sorry that it may not be able to help you.......&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 01:28:52 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457269#M44369</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-12-11T01:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457272#M44370</link>
      <description>&lt;P&gt;I receive the below error -&amp;nbsp;Enter password: ***********&lt;BR /&gt;Failed to establish SSH session or execute command: The term 'New-SSHSession' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was&lt;BR /&gt;included, verify that the path is correct and try again.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 03:31:55 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457272#M44370</guid>
      <dc:creator>manistorage</dc:creator>
      <dc:date>2024-12-11T03:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457278#M44373</link>
      <description>&lt;P&gt;Whether you have downloaded and installed the Posh-SSH module,&lt;/P&gt;&lt;P&gt;Run the following command to install the Posh-SSH module from PowerShell Gallery:&lt;BR /&gt;Install-Module -Name Posh-SSH -Force -AllowClobber&lt;BR /&gt;-Force: forcibly installs the module, even if the module is already installed.&lt;BR /&gt;-AllowClobber: allows existing commands to be overwritten.&lt;/P&gt;&lt;P&gt;Re-import the module Modify the following information to try again&lt;BR /&gt;Import-Module F:\Posh-SSH ---&amp;gt; Import-Module Posh-SSH&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 05:54:17 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/457278#M44373</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-12-11T05:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: powershell script</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/458786#M44697</link>
      <description>&lt;P&gt;If I may ask, why are you invoking SSH rather than using the native PowerShell cmdlets in the toolkit? For example, the output of "cluster show" can be achieved with the following cmdlet (ignore my use of ZapiCall - I'm currently troubleshooting an issue with the REST API not returning proper results and having to fall back on ZAPI):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS:02/21/25 09:15:19 [hostnameredacted]&amp;gt; Get-NcNode -ZapiCall | Format-Table -AutoSize -Property Node,IsNodeHealthy,IsNodeClusterEligible

Node                  IsNodeHealthy IsNodeClusterEligible
----                  ------------- ---------------------
[hostnameredacted]-05          True                  True
[hostnameredacted]-06          True                  True
[hostnameredacted]-07          True                  True
[hostnameredacted]-08          True                  True


PS:02/21/25 09:15:27 [hostnameredacted]&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 14:24:01 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/powershell-script/m-p/458786#M44697</guid>
      <dc:creator>JeffGeb</dc:creator>
      <dc:date>2025-02-21T14:24:01Z</dc:date>
    </item>
  </channel>
</rss>

