有没有办法说"我即将发布一些命令,如果他们无法弄明白为什么,并修复它。"理想情况下,它会给我一个简单的Y / N选项来修复它(无论是一次还是永远)。或者一些覆盖,比如管理员应该如何运行,只是跳过所有权限检查?还是一种关闭权限检查的方法?
这样的事情:
C:>删除打印机GHI
您无法删除打印机WXY,因为1)您没有权限XYZ,以及2)您不是WXY组的成员,3)队列中有4394568个未打印的作业GHI打印机,4)你没有ABC去做DEF,5)你的JKL被设置为MNO。
您希望Windows授予您XYZ的权限,将您添加到WXY组的会员资格,并让ABC进行DEF,将您的JKL设置为PQR并删除4,394,568个未打印的作业,并删除打印机GHI吗? [O / Y / N](仅[O]时间,[Y]永久,[N] o)? ÿ
为域名GHI提供管理员用户名和密码。
用户名:GHI /管理员
密码:密码
打印机GHI已被删除。祝你有愉快的一天。
C:>
答案 0 :(得分:3)
要获取Bash中的历史记录和命令行编辑功能,请查看PSReadline模块。 PowerShell已经有很好的制表完成,但PSReadline使它更好。
BTW PowerShell在使用API方面并不像处理对象那么多。管理打印机非常简单:
8> Get-Printer
Name ComputerName Type DriverName PortName Shared Publishe
d
---- ------------ ---- ---------- -------- ------ --------
Send To OneNote 2013 Local Send to Microsoft OneN... NUL: False False
Quicken PDF Printer Local Amyuni Document Conver... NUL: False False
Microsoft XPS Document Writer Local Microsoft XPS Document... PORTPROMPT: False False
HP Photosmart 7520 Local HP Photosmart 7520 ser... 192.168.1.127_1 False False
hp LaserJet 1300 PCL 5 Local hp LaserJet 1300 PCL 5 DOT4_001 True False
Fax Local Microsoft Shared Fax D... SHRFAX: False False
9> Remove-Printer 'Microsoft XPS Document Writer'
Remove-Printer : Access was denied to the specified resource.
At line:1 char:1
+ Remove-Printer 'Microsoft XPS Document Writer'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (MSFT_Printer (N...= "", Type = 0):ROOT/StandardCimv2/MSFT_Printer) [R
emove-Printer], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Remove-Printer
有更多有用的错误消息的公平点。这就是产品在例如:
中变得越来越好的东西10> Invoke-Command -ComputerName . {Get-Service spooler}
[localhost] Connecting to remote server localhost failed with the following error message : The client cannot connect
to the destination specified in the request. Verify that the service on the destination is running and is accepting
requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly
IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help
topic.
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken