首页 > 系统相关 >powershell 制作工具菜单

powershell 制作工具菜单

时间:2024-02-23 15:58:53浏览次数:36  
标签:DarkCyan 菜单 NoNewline subMenu2 Write Host ForegroundColor 制作 powershell

function mainMenu {
    $mainMenu = 'X'
    while($mainMenu -ne ''){
        Clear-Host
        Write-Host "`n`t`t My Script`n"
        Write-Host -ForegroundColor Cyan "Main Menu"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Submenu1"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Submenu2"
        $mainMenu = Read-Host "`nSelection (leave blank to quit)"
        # Launch submenu1
        if($mainMenu -eq 1){
            subMenu1
        }
        # Launch submenu2
        if($mainMenu -eq 2){
            subMenu2
        }
    }
}

function subMenu1 {
    $subMenu1 = 'X'
    while($subMenu1 -ne ''){
        Clear-Host
        Write-Host "`n`t`t My Script`n"
        Write-Host -ForegroundColor Cyan "Sub Menu 1"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Say hello"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Say goodbye"
        $subMenu1 = Read-Host "`nSelection (leave blank to quit)"
        $timeStamp = Get-Date -Uformat %m%d%y%H%M
        # Option 1
        if($subMenu1 -eq 1){
            Write-Host 'Hello!'
            # Pause and wait for input before going back to the menu
            Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
            Write-Host "`nPress any key to return to the previous menu"
            [void][System.Console]::ReadKey($true)
        }
        # Option 2
        if($subMenu1 -eq 2){
            Write-Host 'Goodbye!'
            # Pause and wait for input before going back to the menu
            Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
            Write-Host "`nPress any key to return to the previous menu"
            [void][System.Console]::ReadKey($true)
        }
    }
}

function subMenu2 {
    $subMenu2 = 'X'
    while($subMenu2 -ne ''){
        Clear-Host
        Write-Host "`n`t`t My Script`n"
        Write-Host -ForegroundColor Cyan "Sub Menu 2"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Show processes"
        Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
            Write-Host -ForegroundColor DarkCyan " Show PS Version"
        $subMenu2 = Read-Host "`nSelection (leave blank to quit)"
        $timeStamp = Get-Date -Uformat %m%d%y%H%M
        # Option 1
        if($subMenu2 -eq 1){
            Get-Process
            # Pause and wait for input before going back to the menu
            Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
            Write-Host "`nPress any key to return to the previous menu"
            [void][System.Console]::ReadKey($true)
            pause
        }
        # Option 2
        if($subMenu2 -eq 2){
            $PSVersionTable.PSVersion
            # Pause and wait for input before going back to the menu
            Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
            Write-Host "`nPress any key to return to the previous menu"
            [void][System.Console]::ReadKey($true)
            pause
        }
        if ($subMenu2 -eq 3){
            $username = Read-Host("`nEnter domain user account")
            if($username -ne "`0"){
                net user $username /domain
                pause
                [void][System.Console]::ReadKey($true)
                
               }else{
                    echo "Invalid entry"
                    [void][System.Console]::ReadKey($true)

               }
            }
    }
}
mainMenu

  

标签:DarkCyan,菜单,NoNewline,subMenu2,Write,Host,ForegroundColor,制作,powershell
From: https://www.cnblogs.com/luoye00/p/18029734

相关文章

  • Android 《PopupWindow 仿微信下拉菜单》
    布局文件popup_menu.xml<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:orientation="ve......
  • 若依+vue3配置菜单后设置缓存但实际上切换页签重复请求接口
    刚接触ruoyi,配置菜单时发现一个问题,配置好了,也设置了缓存,但是切换tab页签还是会重复请求接口,配置如图:仅是举例,如上图,系统管理->角色管理列表配置,路由地址是role,缓存也勾选了,但实际上第一次打开角色管理页签第一次请求了数据,再跳转其他页面,回到角色管理页签时,又一次请求了数据,实......
  • Windows bat批处理+PowerShell获取文件日期 和 时分秒
    前言全局说明Windowsbat批处理+PowerShell获取文件秒一、说明二、分开获取日期和时分秒获取bat文件自身的日期时间和时分秒1.源码文件名:get-file-second.bat@echooffchcp65001>nulecho.echo.setbak_file=get-file-second.bat::获取文件修改时间setloc......
  • PowerShell 脚本来监视并自动重新启动崩溃或挂起的应用程序
    PowerShell脚本来监视并自动重新启动崩溃或挂起的应用程序。以下是一个简单的示例脚本,用于监视并重新启动特定的应用程序:powershellCopyCode#设置要监视的应用程序名称$applicationName="YourApplication.exe"#设置检测时间间隔(秒)$checkInterval=5#循环监视应用......
  • Windows也能拥有好用的命令行吗?Powershell+Terminal折腾记录(v1.0版本)
    PS:本文写于2021年,现在已经是2024年,有了很多新变化,我在接下来的文章里会继续更新。前言Windows一向以图形化操作入门容易著称,所以对于命令行的支持一直为人所诟病,比起Linux或者mac都是被吊打的。这一局面在最近几个版本的Windows10更新里,特别是微软官方出了WindowsTerminal这个大......
  • 配置powershell
    参考视频:配置终端代理:$env:HTTP_PROXY="http://127.0.0.1:10809";$env:HTTPS_PROXY="https://127.0.0.1:10809"安装scoopiwr-usebget.scoop.sh|iex非管理员模式运行psscoop的默认安全策略使得它不能直接在管理员模式下安装;运行以下两个命令:Set-ExecutionPolicyRem......
  • bat+powershell实现win10一键共享
    网卡Ethernet共享给网卡Ethernet2C:\tools\share_net.ps1#RegistertheHNetCfglibrary(once)#regsvr32hnetcfg.dll#CreateaNetSharingManagerobject$m=New-Object-ComObjectHNetCfg.HNetShare#Listconnections$m.EnumEveryConnection|%{$m.NetConnect......
  • C#开源免费的Windows右键菜单管理工具
    前言今天分享一个C#开源、免费、纯粹的Windows右键菜单管理工具:ContextMenuManager。工具主要功能程序支持国际化多语言显示。启用或禁用文件、文件夹、新建、发送到、打开方式、自定义文件格式、IE浏览器、WinX等右键菜单项目。对上述场景右键菜单项目进行修改名称、修改图......
  • DaVinci Resolve Studio 18.6.5 (macOS, Windows) - 剪辑、调色、特效和音频后期制作
    DaVinciResolveStudio18.6.5(macOS,Windows)-剪辑、调色、特效和音频后期制作BlackmagicDesignDaVinciResolveStudio请访问原文链接:DaVinciResolveStudio18.6.5(macOS,Windows)-剪辑、调色、特效和音频后期制作,查看最新版。原创作品,转载请保留出处。作者主页......
  • 在 PowerShell 中,可以使用 Remove-Item 命令来替代 rmdir 命令(在 cmd 窗口下使用)。Rem
    rmdir/?删除一个目录。RMDIR[/S][/Q][drive:]pathRD[/S][/Q][drive:]path  /S   除目录本身外,还将删除指定目录下的所有子目录和      文件。用于删除目录树。  /Q   安静模式,带/S删除目录树时不要求确认 在PowerShell中,可以使......