powershell: 生成随机字符串
ASCII范围内的
获取6个随机字符(字母和数字)
48到57是数字0-9,powershell的范围操作符是..,和Perl 5的一样, 所以 48..57就是指(48 49 50 51 52 53 54 55 56 57)的列表。 65到90是大写字符A到Z,97到122是小写字母。如果需要获取多有的可打印字符(包括空格)的话,范围是32..127。
[char]把对应数字转换成字符,例如 [char](66)就是B(大写字母B),C语言使用的小括号来进行类型强制转换。
# 1
-join((48..57 + 65..90 + 97..122) | get-random -count 6 | %{[char]$_})
# 如果不指定-count参数,则前面的list有多少个字符
# get-random就会获取多少个字符,只是顺序打乱了
# 2
-join(0..1024|%{[char][int]((48..57 + 65..90 + 97..122)| Get-Random)})
# 这里的0..1024相当于循环控制,每循环一次后面的%{[char][int]((48..57 + 65..90 + 97..122)| Get-Random)}执行一次,其中在数字字母中随机选一个字符
# 0..1024, like Perl, loop controller
#-join是
字符连接操作符
# 3
-join ([char[]](65..90+97..122) | Get-Random -Count 6)
function Get-RandomString() {
param(
[int]$length=10,
# 这里的[int]是类型指定
[char[]]$sourcedata
)
for($loop=1; $loop –le $length; $loop++) {
$TempPassword+=($sourcedata | GET-RANDOM | %{[char]$_})
}
return $TempPassword
}
Get-RandomString -length 14 -sourcedata (48..127)
Unicode
引用
1. Powershell Reference 3.0: Get-Random
[2. Generating A New Password With Windows Powershell](from https://blogs.technet.microsoft.com/heyscriptingguy/2013/06/03/generating-a-new-password-with-windows-powershell/)
3. Generate Random Letters With Powershell
4. How do I encode Unicode character codes in a PowerShell string literal?
powershell: 生成随机字符串的更多相关文章
- .net生成随机字符串
生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...
- PHP 生成随机字符串与唯一字符串
说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...
- PHP生成随机字符串包括大小写字母
PHP生成随机字符串包括大小写字母,这里介绍两种方法: 第一种:利用字符串函数操作 <?php /** *@blog <www.phpddt.com> */ function cre ...
- 生成随机字符串(UUID方法)
这是另一种用UUID生成随机字符串的方法. public class RandomGenerator{ private int length; public void setLength(int le ...
- SQL生成随机字符串
1.SQLserve生成随机字符串 SELECT replace(newid(), '-', '')
- php生成随机字符串可指定纯数字、纯字母或者混合的
php 生成随机字符串 可以指定是纯数字 还是纯字母 或者混合的. 可以指定长度的. function rand_zifu($what,$number){ $string=''; for($i = 1 ...
- JS生成随机字符串的多种方法
这篇文章主要介绍了JS生成随机字符串的方法,需要的朋友可以参考下 下面的一段代码,整理电脑时,记录备查. <script language="javascript"> ...
- PHP生成随机字符串与唯一字符串
代码如下: <?php /* * 生成随机字符串 * @param int $length 生成随机字符串的长度 * @param string $char 组成随机字符串的字符串 * @ret ...
- php 生成随机字符串,数字,大写字母,小写字母,特殊字符可以随意组合
* 生成随机字符串* @param int $length 要生成的随机字符串长度* @param string $type 随机码类型:0,数字+大小写字母:1,数字:2, ...
随机推荐
- SendEmail语法
SendEmail语法 示例: /usr/local/bin/sendEmail -f shengwei.tang@joy4you.com -t @qq.com -s smtp.exmail.qq.c ...
- 常用公共的css的样式
html{-webkit-text-size-adjust:none; /*解决chrome浏览器下字体不能小于12px*/} body{overflow-x: hidden; font-size:1 ...
- PHP5下SOAP调用实现过程
本文以某公司iPhone 6手机预约接口开发为例,介绍PHP5下SOAP调用的实现过程. 一.基础概念 SOAP(Simple Object Access Protocol )简单对象访问协议是在分散 ...
- php Memcache
<?php $mem = new Memcache();//实例化一个对象 $mem->connect("localhost",11211);//连接memcache服 ...
- [BS] 小知识点总结-02
1. dispatch_GCD 可让某操作延迟x秒执行 //模拟网速慢,延迟3s返回数据(就会导致右侧数据和左侧标签不对应) dispatch_after(dispatch_time(DISPATC ...
- Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- InitializingBean afterPropertiesSet
package org.test.InitializingBean; import org.springframework.context.support.ClassPathXmlApplicatio ...
- Oracle Flashback Technologies - 闪回被drop的表
Oracle Flashback Technologies - 闪回被drop的表 在oracle10g中,drop一个表后,表没有真正被删除,支持被rename后放在recyclebin中. #新建 ...
- Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量
Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量 v$flashback_database_stat监控闪回数据的i/o开销的统计信息,根据之前的系统负载 ...
- EBS R12.2安装,使用的操作系统用户
在安装时,错误使用了oracle rdbms的对应的操作系统用户,导致安装前,验证时"web server install prerequisites"选项验证失败: (本图其它两 ...