Powershell基础语法

设置powershell执行策略

  • 查看当前策略
    Get-ExecutionPolicy

  • 设置策略
    Set-ExecutionPolicy Bypass -Scope CurrentUser

  • 策略描述

AllSigned: 可运行所有命令和脚本,但是脚本必须签名否则会提示报警
Bypass: 可运行所有命令和脚本
RemoteSigned: 可运行所有命令和脚本,但远程脚本必须签名,本地不需要
Restricted: 可以运行单个命令不允许运行脚本
Unrestricted: 未签名的脚本可以运行

模块

  • 安装模块
Install-Module -Name DataGateway -Scope CurrentUser

如果在安装显示如下报错“file 'DataGateway.Profile.psd1' is not valid.”请增加如下参数
Install-Module -Name datagateway -Scope CurrentUser -force -SkipPublisherCheck -AllowClobber

如果在使用命令时报错“The 'Connect-AzureAD' command was found in the module 'AzureAD', but the module could not be loaded. For more
information, run 'Import-Module AzureAD'.”,请增加如下参数
Set-ExecutionPolicy Unrestricted -Scope CurrentUser

  • 查看模块
Get-InstalledModule
  • 卸载模块
Get-Module DataGateway* -ListAvailable | Uninstall-Module -Force
  • 查看模块有什么命令
Get-command -module datagateway*

类型转换

$SignInName = "HZ427280"
$SignInNames = $SignInName -as [Microsoft.Open.AzureAD.Model.SignInName]
posted @ 2022-10-19 10:48  罐头瓶  阅读(41)  评论(0编辑  收藏  举报