-
Notifications
You must be signed in to change notification settings - Fork 2
/
Generate SAN Zones for Cisco or Brocade with UCS
1922 lines (1793 loc) · 64.6 KB
/
Generate SAN Zones for Cisco or Brocade with UCS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
https://communities.cisco.com/docs/DOC-37346
This script will generate the Aliases, Zones and Zone Sets for either Brocade or Cisco MDS/Nexus.
The script only build Single Initiator/Single Target Zoning
It uses a pre-defined CSV file of SAN target information along with information gathered by UCSM. A sample has been included in this ZIP file.
It allows you to save the configuration files to your drive or to write directly to your equipment with SSH.
It will generate the information for either all Service Profiles with vHBAs or selected ones via a multi-select menu.
Prerequisites for this script are:
PowerShell must be enabled on your client computer. - set-executionpolicy unrestricted -force
You must be running PowerShell version 3 or above
You must download and install Cisco PowerTool for PowerShell from http://www.cisco.com. A CCO Login is required
You must download plink.exe and place in the correct folder
You can download plink here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
It is assumed plink will be located in this folder: C:\Program Files (x86)\PuTTY\plink.exe
But you can change this in the script. Search for $PlinkAndPath and edit
You must be network connected and have reachability via SSH TCP Port 22 to your SAN Fabric Switches/Directors
You must be network connected and have reachability via SSL TCP Port 443 to your Cisco UCS Domain
You must have a login into your UCSM domain
You must have a login into your SAN Fabric Switches/Directors
You must have this script and the required CSV file in the same folder
If outputting configurations to a file they will also be saved in the same folder as this script and CSV file
The script supports Service Profiles with vHBAs for:
Two vHBAs: A & B Fabric
One vHBA: A Fabric
One vHBA: B Fabric
It does NOT support having some Service Profiles with only an A fabric vHBA and some with only a B fabric vHBA or
where some have two vHBAs and others only have one.
The scripts tested limits are building Single Initiator/Single Target Zones is 160 Service Profiles against a 32 Port
SAN Array (16 A and 16 B controller ports). This is 2560 Aliases, Zones and Zone Set members per fabric.
This is not a maximum, but a maximum tested.
It takes only a few seconds to build configurations written to file
It took ~1 second to build each zone when pushing to an MDS switch and ~4 seconds to build each zone when pushing to a Brocade switch
For 2560 zones it took 21 minutes to the MDS and 114 minutes to the brocade for each fabric so be patient when writing to your equipment.
v0.3 - Initial published version
v0.4 - Added the ability to create all or selected zones
v0.4.01 - Minor features to adjust screen colors and menu locations for a better user experience
v0.5 - Added error handling for new zoning menu
v0.5.01 - Bug fix. When select only the last item in the Service Profile Menu, it build 2 zones, one correct, one blank.
v0.5.02 - Now checks that you are running at least PowerShell v3
v0.5.03 - Fixed issue with single FI deployment
v0.5.05 - Added built in help. Command line options. Standard naming convention.
v0.5.0.7 - Added support for different quantities of ports per fabric. Added support for a saved credentials file
v0.5.0.8 - Fixed an issue with generating configuration in a UCS with a single Service Profile
As always, let me know if you have any questions, comments or concerns.
Joe
New-UcsFcZoning.zip (11.9 K)
##############
<#
.SYNOPSIS
Generates SAN zoning information for UCS managed servers connected to Cisco or Brocade fabrics
.DESCRIPTION
This script will take a CSV file of SAN Information and use information gathered from UCSM to generate Fibre Channel Zones and Zonesets for either Cisco or Brocade SAN Switches. It allows you to save the configuration files to your drive or to write them directly to your equipment.
.EXAMPLE
New-UcsFcZoning.ps1
This script can be run without any command line parameters. User will be prompted for all parameters and options required
.EXAMPLE
New-UcsFcZoning.ps1 -req "y" -ucs "1.2.3.4" -ucred -serviceprofile "one, two, etc" -manufacture "Cisco" -wwpn "WWPN xxxx.csv" -output "Equipment" -fabrica "2.3.4.5" -acred -fabricb "3.4.5.6" -bcred
-req -- Acknowledge that required prerequisites have been met -- Valid options are: Y or N
-ucs -- UCS Manager IP or Host Name -- Example: 1.2.3.4 or myucs or myucs.domain.local
-ucred -- UCS Manager Credential Switch -- Adding this switch will immediately prompt you for your UCSM username and password
-serviceprofile -- Service Profile name or names to create zones for -- Valid options are: SingleName or NameOne,NameTwo,ETC or All
-manufacture -- SAN fabric manufacture -- Valid options are: Cisco or Brocade
-wwpn -- WWPN targets CSV file -- Example: WWPN xxxxxx.csv (File name must start with: WWPN)
-output -- Destination of configuration -- Valid options are: File or Equipment
-fabrica -- SAN Fabric A IP or Host Name -- Example: 2.3.4.5 or mysana or mysana.domain.local
-acred -- SAN Fabric A Credential Switch -- Adding this switch will immediately prompt you for your SAN Fabric A username and password
-fabricb -- SAN Fabric B IP or Host Name -- Example: 3.4.5.6 or mysanb or mysana.domain.local
-bcred -- SAN Fabric B Credential Switch -- Adding this switch will immediately prompt you for your SAN Fabric B username and password
All parameters are optional and any skipped will be prompted for during execution
The only prompts that will always be presented to the user will be for User Names and Passwords
.EXAMPLE
New-UcsFcZoning.ps1 -req "y" -ucs "1.2.3.4" -ucred -serviceprofile "All" -manufacture "Brocade" -wwpn "WWPN xxxx.csv" -output "File"
-req -- Acknowledge that required prerequisites have been met -- Valid options are: Y or N
-ucs -- UCS Manager IP or Host Name -- Example: 1.2.3.4 or myucs or myucs.domain.local
-ucred -- UCS Manager Credential Switch -- Adding this switch will immediately prompt you for your UCSM username and password
-serviceprofile -- Service Profile name or names to create zones for -- Valid options are: SingleName or NameOne,NameTwo,ETC or All
-manufacture -- SAN fabric manufacture -- Valid options are: Cisco or Brocade
-wwpn -- WWPN targets CSV file -- Example: WWPN xxxxxx.csv (File name must start with: WWPN)
-output -- Destination of configuration -- Valid options are: File or Equipment
All parameters are optional and any skipped will be prompted for during execution
The only prompts that will always be presented to the user will be for User Names and Passwords
.EXAMPLE
New-UcsFcZoning.ps1 -req "y" -ucs "1.2.3.4" -usaved "myucscred.csv" -serviceprofile "All" -manufacture "Cisco" -wwpn "WWPN xxxx.csv" -output "Equipment" -fabrica "2.3.4.5" -asaved "myacred.csv" -fabricb "3.4.5.6" -bsaved "mybcred.csv" -skiperrors
-req -- Acknowledge that required prerequisites have been met -- Valid options are: Y or N
-ucs -- UCS Manager IP or Host Name -- Example: 1.2.3.4 or myucs or myucs.domain.local
-usavedcred -- UCSM credentials file -- Example: -usavedcred "myucscred.csv"
To create a credentials file: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} |Export-CSV -NoTypeInformation .\myucscred.csv
Make sure the password file is located in the same folder as the script
-serviceprofile -- Service Profile name or names to create zones for -- Valid options are: SingleName or NameOne,NameTwo,ETC or All
-manufacture -- SAN fabric manufacture -- Valid options are: Cisco or Brocade
-wwpn -- WWPN targets CSV file -- Example: WWPN xxxxxx.csv (File name must start with: WWPN)
-output -- Destination of configuration -- Valid options are: File or Equipment
-fabrica -- SAN Fabric A IP or Host Name -- Example: 2.3.4.5 or mysana or mysana.domain.local
-asavedcred -- Fabric A credentials file -- Example: -asavedcred "myacred.csv"
To create a credentials file: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} |Export-CSV -NoTypeInformation .\myacred.csv
Make sure the password file is located in the same folder as the script
-fabricb -- SAN Fabric B IP or Host Name -- Example: 3.4.5.6 or mysanb or mysana.domain.local
-bsavedcred -- Fabric B credentials file -- Example: -bsavedcred "mybcred.csv"
To create a credentials file: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} |Export-CSV -NoTypeInformation .\mybcred.csv
Make sure the password file is located in the same folder as the script
-skiperrors -- Tells the script to skip any prompts for errors and continues with 'y'
All parameters are optional and any skipped will be prompted for during execution
The only prompts that will always be presented to the user will be for User Names and Passwords
.NOTES
Author: Joe Martin
Email: [email protected]
Company: Cisco Systems, Inc.
Version: v0.5.08
Date: 2/12/2015
Disclaimer: Code provided as-is. No warranty implied or included. This code is for example use only and not for production
.INPUTS
UCSM IP Address or Hostname
UCSM Username and Password
UCSM Credentials File
Select Service Profiles to Zone
Select Cisco or Brocade for Zoning
Select WWPN targets CSV file
Select output to File or Equipment to SAN Switches
If Equipment selected, Fabric A IP Address or Hostname
If Equipment selected, Fabric A Username and Password
If Equipment selected, Fabric B IP Address or Hostname
If Equipment selected, Fabric B Username and Password
.OUTPUTS
If File selected for output, two files will be created in the same directory as the script resides.
File format are .TXT
.LINK
http://communities.cisco.com/people/joemar/content
#>
#Command Line Parameters
param(
[string]$REQUIREMENTSMET, # Y or N
[string]$UCSM, # IP Address or Hostname
[switch]$UCREDENTIALS, # UCSM Credentials (Username and Password)
[string]$USAVEDCRED, # Saved UCSM Credentials. To create do: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} | Export-CSV -NoTypeInformation .\myucscred.csv
[string]$SERVICEPROFILES, # ALL or Service Profile Name or list of Service Profile Names separated by commas
[string]$MANUFACTURE, # Cisco or Brocade
[string]$WWPNCSV, # WWPN xxxx.csv file located in the same directory as the script
[string]$OUTPUT, # File or Equipment
[string]$FABRICA, # IP Address or Hostname of SAN Fabric A
[string]$ASAVEDCRED, # Saved Fabric A Credentials. To create do: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} | Export-CSV -NoTypeInformation .\myacred.csv
[switch]$ACREDENTIALS, # Fabric A Credentials (Username and Password)
[string]$FABRICB, # IP Address or Hostname of SAN Fabric B
[string]$BSAVEDCRED, # Saved Fabric B Credentials. To create do: $credential = Get-Credential ; $credential | select username,@{Name="EncryptedPassword";Expression={ConvertFrom-SecureString $_.password}} | Export-CSV -NoTypeInformation .\mybcred.csv
[switch]$BCREDENTIALS, # Fabric B Credentials (Username and Password)
[switch]$SKIPERROR # Skip any prompts for errors and continues with 'y'
)
#Clear the screen
clear-host
#Show user that script has started
Write-Output "Script Running..."
#Gather any credentials requested from command line
if ($UCREDENTIALS)
{
Write-Output ""
Write-Output "Enter UCSM Credentials"
$credu = Get-Credential -Message "Enter UCSM Credentials"
}
if ($ACREDENTIALS)
{
Write-Output ""
Write-Output "Enter Fabric A Credentials"
$creda = Get-Credential -Message "Enter SAN Fabric A Credentials"
}
if ($BCREDENTIALS)
{
Write-Output ""
Write-Output "Enter Fabric B Credentials"
$credb = Get-Credential -Message "Enter SAN Fabric B Credentials"
}
#Change directory to the script root
cd $PSScriptRoot
#Check to see if credential files exists
if ($USAVEDCRED)
{
if ((Test-Path $USAVEDCRED) -eq $false)
{
Write-Output ""
Write-Output "Your credentials file $USAVEDCRED does not exist in the script directory"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
}
if ($ASAVEDCRED)
{
if ((Test-Path $ASAVEDCRED) -eq $false)
{
Write-Output ""
Write-Output "Your credentials file $ASAVEDCRED does not exist in the script directory"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
}
if ($BSAVEDCRED)
{
if ((Test-Path $BSAVEDCRED) -eq $false)
{
Write-Output ""
Write-Output "Your credentials file $BSAVEDCRED does not exist in the script directory"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
}
#Tell user what the script does
Write-Output ""
Write-Output "Overview:"
Write-Output " This script will generate the Aliases, Zones and Zone Sets for either"
Write-Output " Brocade or Cisco MDS/Nexus."
Write-Output " The script builds Single Initiator/Single Target Zones as this"
Write-Output " is the standard recommended and supported by most array"
Write-Output " manufactures."
Write-Output " It uses a pre-defined CSV file of SAN target information along with"
Write-Output " information gathered by UCSM."
Write-Output " It allows you to save the configuration files to your drive or to write"
Write-Output " directly to your equipment with SSH."
Write-Output " It will generate the information for all Service Profiles with vHBAs or"
Write-Output " selected ones."
Write-Output ""
Write-Output "Prerequisites for this script are:"
Write-Output " PowerShell must be enabled on your client computer."
Write-Output " Example: set-executionpolicy unrestricted -force"
Write-Output " You must be running PowerShell version 3 or above."
Write-Output " You must download and install Cisco PowerTool for PowerShell from:"
Write-Output " http://www.cisco.com"
Write-Output " A CCO Login is required."
Write-Output " You must download plink.exe and place it in the same folder as this"
Write-Output " script and CSV targets file."
Write-Output " You can download plink.exe here:"
Write-Output " http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html"
Write-Output " plink.exe license can be found here:"
Write-Output " http://www.chiark.greenend.org.uk/~sgtatham/putty/licence.html"
Write-Output " It is assumed plink will be located in this folder:"
Write-Output " $PSScriptRoot"
Write-Output " But you can change this in the script."
write-output ' Search for: $PlinkAndPath'
Write-Output " and edit to match the location of your choice."
Write-Output " You must be network connected and have reachability via SSH TCP Port 22"
Write-Output " to your SAN Fabric Switches/Directors."
Write-Output " You must be network connected and have reachability via SSL TCP Port"
Write-Output " 443 to your Cisco UCS Domain."
Write-Output " You must have a login into your UCSM domain with appropriate rights."
Write-Output " You must have a login into your SAN Fabric Switches/Directors with"
Write-Output " appropriate rights."
Write-Output " You must have this script and the required WWPN targets CSV file in the"
Write-Output " same folder."
Write-Output " If outputting configurations to a file they will also be saved in the"
Write-Output " same folder as this script and WWPN targets CSV file."
Write-Output ""
Write-Output "The script supports Service Profiles with vHBAs for:"
Write-Output " Two vHBAs: A & B Fabric."
Write-Output " One vHBA: A Fabric."
Write-Output " One vHBA: B Fabric."
Write-Output " It does NOT support having some Service Profiles with only an A"
Write-Output " fabric vHBA and some with only a B fabric vHBA or where some"
Write-Output " have two vHBAs and others only have one."
Write-Output ""
Write-Output "Scalability and Performance:"
Write-Output " The scripts tested limits are building Single Initiator/Single Target"
Write-Output " Zones is 160 Service Profiles against a 32 Port SAN Array (16 A and 16"
Write-Output " B controller ports). This is 2560 Aliases, Zones and Zone Set members "
Write-Output " per fabric."
Write-Output " This is not a maximum, but a maximum tested."
Write-Output " It takes only a few seconds to build configurations written to file."
Write-Output " It took ~1 second to build each zone when pushing to an MDS switch and"
Write-Output " ~4 seconds to build each zone when pushing to a Brocade switch."
Write-Output " For 2560 zones it took 21 minutes to the MDS and 114 minutes to"
Write-Output " the brocade for each fabric so be patient when writing to your"
Write-Output " equipment."
Write-Output ""
Write-Output "How it works:"
Write-Output " The script logs into a UCSM Domain and collects information about the"
Write-Output " VSANS in use, The Service Profiles and their attached vHBA WWPNs."
Write-Output " The script then reads the WWPN CSV file which contains the name of"
Write-Output " the zoneset to be used in the fabric along with the names and WWPNs of"
Write-Output " the Array targets."
Write-Output " The script then builds aliases, zones and zonesets based on the"
Write-Output " commands for either Cisco or Brocade."
Write-Output " Finally the script outputs the configurations to either file or will"
Write-Output " SSH directly into your SAN fabric and writes the configuration to your"
Write-Output " fabric."
Write-Output ""
#Have you met all the prerequisites and want to proceed
if (($REQUIREMENTSMET -ieq "y") -or ($REQUIREMENTSMET -ieq "n"))
{
$Choice = $REQUIREMENTSMET
}
else
{
$Choice = Read-Host "Have you met the above prerequisites? (Y/N)"
}
if ($Choice -ieq "y")
{
Write-Output ""
}
elseif ($Choice -ieq "n")
{
Write-Output "You have chosen to exit"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output "You have selected an invalid option"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Verify PowerShell Version for script support
$PSVersion = $psversiontable.psversion
$PSMinimum = $PSVersion.Major
if ($PSMinimum -ge "3")
{
}
else
{
Write-Output "This script requires PowerShell version 3 or above"
Write-Output "Please update your system and try again."
Write-Output "You can download PowerShell updates here:"
Write-Output " http://search.microsoft.com/en-us/DownloadResults.aspx?rf=sp&q=powershell+4.0+download"
Write-Output "If you are running a version of Windows before 7 or Server 2008R2 you need to update to be supported"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Set error action preference
#$ErrorActionPreference = "SilentlyContinue"
#$ErrorActionPreference = "Stop"
#$ErrorActionPreference = "Continue"
#$ErrorActionPreference = "Inquire"
$ErrorLevel = "SilentlyContinue"
$ErrorActionPreference = $ErrorLevel
#Load the UCS PowerTool
Write-Output "Checking Cisco PowerTool"
$PowerToolLoaded = $null
$Modules = Get-Module
$PowerToolLoaded = $modules.name
if ( -not ($Modules -like "ciscoUcsPs"))
{
Write-Output " Loading Module: Cisco UCS PowerTool Module"
Import-Module ciscoUcsPs
$Modules = Get-Module
if ( -not ($Modules -like "ciscoUcsPs"))
{
Write-Output ""
Write-Output "Cisco UCS PowerTool Module did not load. Please correct his issue and try again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output " PowerTool is Loaded"
}
}
else
{
Write-Output " PowerTool is Loaded"
}
#Location of plink.exe application
#Make sure to place it in the following folder or update the path below
$PlinkAndPath = "$PSScriptRoot\plink.exe"
#Validate plink installed in identified folder
Write-Output ""
Write-Output "Validating that plink.exe is located in the correct folder"
if (Test-Path $PlinkAndPath)
{
Write-Output " plink.exe is located in the specified folder:"
Write-Output " $PlinkAndPath"
}
else
{
Write-Output " plink.exe is MISSING. Please download and place in the specified folder: $PlinkAndPath"
Write-Output " You can download from: You can download plink here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Define UCS Domain(s)
Write-Output ""
Write-Output "Connecting to UCSM"
if ($UCSM -ne "")
{
$myucs = $UCSM
}
else
{
$myucs = Read-Host "Enter UCS system IP or Hostname"
}
if (($myucs -eq "") -or ($myucs -eq $null) -or ($Error[0] -match "PromptingException"))
{
Write-Output ""
Write-Output "You have provided invalid input."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Disconnect-Ucs
}
#Test that UCSM is IP Reachable via Ping
Write-Output ""
Write-Output "Testing reachability to UCSM"
$ping = new-object system.net.networkinformation.ping
$results = $ping.send($myucs)
if ($results.Status -ne "Success")
{
Write-Output " Can not access UCSM $myucs by Ping"
Write-Output ""
Write-Output "It is possible that a firewall is blocking ICMP (PING) Access."
if ($SKIPERROR)
{
$Try = "y"
}
else
{
$Try = Read-Host "Would you like to try to log in anyway? (Y/N)"
}
if ($Try -ieq "y")
{
Write-Output ""
Write-Output "Trying to log in anyway!"
}
elseif ($Try -ieq "n")
{
Write-Output ""
Write-Output "You have chosen to exit"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output ""
Write-Output "You have provided invalid input. Please enter (Y/N) only."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
}
else
{
Write-Output " Successfully pinged UCSM: $myucs"
}
#Allow Logins to single or multiple UCSM systems
$multilogin = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $false
#Log into UCSM
Write-Output ""
Write-Output "Logging into UCSM"
#Verify PowerShell Version to pick prompt type
if (!$UCREDENTIALS)
{
if (!$USAVEDCRED)
{
if ($PSMinimum -ge "3")
{
Write-Output " Enter your UCSM credentials"
$credu = Get-Credential -Message "UCSM(s) Login Credentials" -UserName "admin"
}
else
{
Write-Output " Enter your UCSM credentials"
$credu = Get-Credential
}
}
else
{
$CredFile = import-csv $USAVEDCRED
$Username = $credfile.UserName
$Password = $credfile.EncryptedPassword
$credu = New-Object System.Management.Automation.PsCredential $Username,(ConvertTo-SecureString $Password)
}
}
#Log into UCSM
$myCon = Connect-Ucs $myucs -Credential $credu
#Check to see if log in was successful
if (($myucs | Measure-Object).count -ne ($myCon | Measure-Object).count)
{
Write-Output " Error Logging into UCS."
Write-Output " Make sure your user has login rights the UCS system and has the"
Write-Output " proper role/privledges to use this tool..."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
if (!$UCREDENTIALS)
{
Write-Output " Login Successful"
}
else
{
Write-Output " Login Successful"
}
}
#Gather vHBA Information
Write-Output ""
Write-Output "Gathering vHBA information from UCSM"
$AllvHBAsA = Get-UcsVhba | where {($_.Addr -ine "derived") -and ($_.SwitchID -eq "A")}
$AllvHBAsB = Get-UcsVhba | where {($_.Addr -ine "derived") -and ($_.SwitchID -eq "B")}
#Put vHBA Info into a Hash Table
if ($AllvHBAsA.count -ne 0)
{
$vHBAInfo = @{"ServiceProfile" = $AllvHBAsA.Dn; "WWPNa" = $AllvHBAsA.Addr; "WWPNb" = $AllvHBAsB.Addr; "WWNN" = $AllvHBAsA.NodeAddr}
}
elseif ($AllvHBAsB.Count -ne 0)
{
$vHBAInfo = @{"ServiceProfile" = $AllvHBAsB.Dn; "WWPNa" = $AllvHBAsA.Addr; "WWPNb" = $AllvHBAsB.Addr; "WWNN" = $AllvHBAsB.NodeAddr}
}
#Check to see if any service profiles have vHBAs
if ($vHBAInfo.ServiceProfile -eq $null)
{
Write-Output ""
Write-Output " No Service Profiles configured with vHBAs"
Write-Output " Please correct and run this script again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output " Information collected"
}
if ($SERVICEPROFILES -eq "")
{
#Offer user to build all or selected zones
Write-Output ""
Write-Output "Do you wish to create zoning information for ALL service profiles or selected?"
Write-Output " Press CANCEL or hit Esc to exit the script"
Write-Output " You can select multiple entries by holding the control key to pick"
Write-Output " individuals or hold the Shift key to select a range, or any combination."
#Multi-Select routine example provided at: http://technet.microsoft.com/en-us/library/ff730950.aspx
$Script:SelectedObjects = @()
$Script:Exit = 'n'
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Service Profiles"
$objForm.Size = New-Object System.Drawing.Size(300,600)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{
foreach ($objItem in $objListbox.SelectedItems)
{$Script:SelectedObjects += $objItem}
$objForm.Close()
}
})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close(); Write-Output "" ; Write-Output "You pressed Escape"; Write-Output " exiting..."; Disconnect-Ucs; $Script:Exit = "y"}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,500)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click(
{
foreach ($objItem in $objListbox.SelectedItems)
{$Script:SelectedObjects += $objItem}
$objForm.Close()
})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,500)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close(); Write-Output ""; Write-Output "You pressed Cancel"; Disconnect-Ucs; $Script:Exit = "y"})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Select from below. SHIFT or CNTRL for multi-select:"
$objForm.Controls.Add($objLabel)
$objListbox = New-Object System.Windows.Forms.Listbox
$objListbox.Location = New-Object System.Drawing.Size(10,40)
$objListbox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Sorted = $True
$objListbox.SelectionMode = "MultiExtended"
if ($vHBAInfo.serviceprofile.count -ne 1)
{
[void] $objListbox.Items.Add("--ALL--")
}
foreach ($SP in $vHBAInfo.ServiceProfile)
{
$ServiceProfileFull = $SP -match "/ls-(?<content>.*)/fc-"
$ServiceProfile = $matches['content']
[void] $objListbox.Items.Add($ServiceProfile)
}
$objListbox.Height = 450
$objForm.Controls.Add($objListbox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
}
elseif ($SERVICEPROFILES -ieq "all")
{
$Script:SelectedObjects = "--ALL--"
}
else
{
[array]$SPArray = ($SERVICEPROFILES.split(",")).trim()
$Script:SelectedObjects = $SPArray
}
if (($Script:SelectedObjects.Count -ne 1) -and ($Script:SelectedObjects -eq "--ALL--"))
{
Write-Output ""
Write-Output "ERROR. If selecting ALL, can only select ALL"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
if ($Script:SelectedObjects -eq "--ALL--")
{
#Hold for future use
}
else
{
$TempServiceProfile = @()
$TempWWPNa = @()
$TempWWPNb = @()
$TempWWNN = @()
$Count = $vHBAInfo.ServiceProfile.Count
if ($Count -eq 1)
{
$ServiceProfileFull = $vHBAInfo.ServiceProfile -match "/ls-(?<content>.*)/fc-"
$ServiceProfile = $matches['content']
$TempServiceProfile += $vHBAInfo.ServiceProfile
$TempWWPNa += $vHBAInfo.WWPNa
$TempWWPNb += $vHBAInfo.WWPNb
$TempWWNN += $vHBAInfo.WWNN
}
else
{
foreach ($Item in $Script:SelectedObjects)
{
$LoopCount = 0
do
{
$ServiceProfileFull = $vHBAInfo.ServiceProfile[$LoopCount] -match "/ls-(?<content>.*)/fc-"
$ServiceProfile = $matches['content']
if ($ServiceProfile -eq $Item)
{
$TempServiceProfile += $vHBAInfo.ServiceProfile[$LoopCount]
$TempWWPNa += $vHBAInfo.WWPNa[$LoopCount]
$TempWWPNb += $vHBAInfo.WWPNb[$LoopCount]
$TempWWNN += $vHBAInfo.WWNN[$LoopCount]
}
$LoopCount += 1
}
while ($LoopCount -le $Count)
}
}
$vHBAInfo = $null
$vHBAInfo = @{"ServiceProfile" = $TempServiceProfile; "WWPNa" = $TempWWPNa; "WWPNb" = $TempWWPNb; "WWNN" = $TempWWNN}
}
}
if ($Script:Exit -eq "y")
{
Write-Output ""
Write-Output "You have chosen to Exit"
Write-Output " Exiting..."
exit
}
if ($Script:SelectedObjects.Count -eq 0)
{
Write-Output ""
Write-Output "You didn't select anything"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Gather vSAN Information
Write-Output ""
Write-Output "Collecting vSAN information from UCSM"
$vSANa = Get-UcsFiSanCloud -Id "A" | get-UcsVsan
$vSANaID = $vSANa.id
$vSANb = Get-UcsFiSanCloud -Id "B" | get-UcsVsan
$vSANbID = $vSANb.id
#Check to see if vSANs are configured in the SAN Cloud
if (($vSANaID -eq $null) -and ($vSANbID -eq $null))
{
Write-Output ""
Write-Output " No vSAN(s) configured in the SAN Cloud of your UCS"
Write-Output " Please correct and run this script again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output " Information collected"
}
#Create list of Config Files
if ($MANUFACTURE -eq "")
{
Write-Output ""
Write-Output "Select Manufacturer from pulldown (Cisco / Brocade / Exit)"
[array]$DropDownArray = $null
foreach ($CFs in $ConfigFiles)
{
[array]$DropDownArray += $CFs.Name
}
#Menu Function for SAN Fabric - Brocade or Cisco
function Return-DropDown
{
$Choice = $DropDown.SelectedItem.ToString()
$Form.Close()
}
#Generate GUI input box for Config File Selection
# Script examples provided at: http://technet.microsoft.com/en-us/library/ff730949.aspx
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
$Form = New-Object System.Windows.Forms.Form
$Form.width = 700
$Form.height = 150
$Form.StartPosition = "CenterScreen"
$Form.Text = ”SAN Fabric Manufacturer to Configure”
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(550,30)
$DropDown.Items.Add("Cisco") | Out-Null
$DropDown.Items.Add("Brocade") | Out-Null
$DropDown.Items.Add("EXIT") | Out-Null
$Form.Controls.Add($DropDown)
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(1,10)
$DropDownLabel.size = new-object System.Drawing.Size(255,20)
$DropDownLabel.Text = "Manufacturer"
$Form.Controls.Add($DropDownLabel)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(300,50)
$Button.Size = new-object System.Drawing.Size(75,25)
$Button.Text = "Select"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog() | Out-Null
}
else
{
$Dropdown = @{"SelectedItem" = $MANUFACTURE}
}
#Check for valid entry
if ($DropDown.SelectedItem -eq $null)
{
Write-Output ""
Write-Output "Nothing Selected"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Check to see if EXIT selected
if ($DropDown.SelectedItem -eq "EXIT")
{
Write-Output ""
Write-Output "You have chosen to EXIT the script"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Set SAN Fabric Manufacture
$SANFabric = $DropDown.SelectedItem
Write-Output " Generating configuration for: $SANFabric"
#Get Data File
$ConfigFiles = dir "WWPN*.csv"
if ($ConfigFiles -eq "")
{
Write-Output ""
Write-Output "Input CSV file must start with WWPN as in WWPN_List.csv and be located in: $PSScriptRoot"
Write-Output ""
Write-Output "Input CSV file must be formatted as below:"
Write-Output "ZoneSetName , NameA , WWPN_A , NameB , WWPN_B"
Write-Output "LabFabric , Cntrl-A-1 , 50:00:00:00:00:00:AA:11 , Cntrl-A-2 , 50:00:00:00:00:00:AB:22"
Write-Output " , Cntrl-A-3 , 50:00:00:00:00:00:AA:33 , Cntrl-A-4 , 50:00:00:00:00:00:AB:44"
Write-Output " , Cntrl-B-1 , 50:00:00:00:00:00:BA:15 , Cntrl-B-2 , 50:00:00:00:00:00:BB:26"
Write-Output " , Cntrl-B-3 , 50:00:00:00:00:00:BA:37 , Cntrl-B-4 , 50:00:00:00:00:00:BB:48"
Write-Output ""
Write-Output "ZoneSetName is the name of the Zone Set"
Write-Output "NameA is the name of the array controller port connecting for SAN fabric A"
Write-Output "WWPN_A is the WWPN of the array controller port connecting to SAN fabric A"
Write-Output "NameB is the name of the array controller port connecting for SAN fabric B"
Write-Output "WWPN_B is the WWPN of the array controller port connecting to SAN fabric B"
Write-Output ""
Write-Output " Please correct this issue and try again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
elseif ($WWPNCSV -eq "")
{
Write-Output ""
Write-Output "Select CSV File from pulldown (CSV files or EXIT)"
}
<# Sample CSV file and format. Save this as WWPNtest.csv and then open in Excel to see the format and then create your own real version.
ZoneSetName,NameA,WWPN_A,NameB,WWPN_B
LabFabric,Cntrl-A-1,50:00:00:00:00:00:AA:11,Cntrl-A-2,50:00:00:00:00:00:AB:22
,Cntrl-A-3,50:00:00:00:00:00:AA:33,Cntrl-A-4,50:00:00:00:00:00:AB:44
,Cntrl-B-1,50:00:00:00:00:00:BA:15,Cntrl-B-2,50:00:00:00:00:00:BB:26
,Cntrl-B-3,50:00:00:00:00:00:BA:37,Cntrl-B-4,50:00:00:00:00:00:BB:48
#>
#Create list of Config Files
if ($WWPNCSV -eq "")
{
[array]$DropDownArray = $null
foreach ($CFs in $ConfigFiles)
{
[array]$DropDownArray += $CFs.Name
}
#Menu Function
function Return-DropDown
{
$Choice = $DropDown.SelectedItem.ToString()
$Form.Close()
}
[array]$DropDownArray += "EXIT"
#Generate GUI input box for Config File Selection
# Script examples provided at: http://technet.microsoft.com/en-us/library/ff730949.aspx
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
$Form = New-Object System.Windows.Forms.Form
$Form.width = 700
$Form.height = 150
$Form.StartPosition = "CenterScreen"
$Form.Text = ”WWPN Targets List CSV to use”
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(550,30)
ForEach ($Item in $DropDownArray)
{
$DropDown.Items.Add($Item) | Out-Null
}
$Form.Controls.Add($DropDown)
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(1,10)
$DropDownLabel.size = new-object System.Drawing.Size(255,20)
$DropDownLabel.Text = "CSV File"
$Form.Controls.Add($DropDownLabel)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(300,50)
$Button.Size = new-object System.Drawing.Size(75,25)
$Button.Text = "Select"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog() | Out-Null
}
else
{
$Dropdown = @{"SelectedItem" = $PSScriptRoot+"\"+$WWPNCSV}
}
#Check for valid entry
if ($DropDown.SelectedItem -eq $null)
{
Write-Output ""
Write-Output "Nothing Selected"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Check to see if EXIT selected
if ($DropDown.SelectedItem -eq "EXIT")
{
Write-Output ""
Write-Output "You have chosen to EXIT the script"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
#Load the data configuration file
$CSVFile = $DropDown.SelectedItem
$CSVFileDir = $PSScriptRoot
cd $CSVFileDir
$TargetInfo = Import-Csv $CSVFile
#Validating data file
Write-Output ""
Write-Output "Validating Data File"
$FileThere = Test-Path $CSVFile
if ($FileThere -eq $false)
{
Write-Output ""
Write-Output "The WWPN Targets file specified does not exist"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
$CharacterTest = [regex]"^[A-Za-z0-9_-]*$"
$WWPNtest = [regex]"^[a-fA-F0-9:]*$"
if ((($TargetInfo.ZoneSetName[0]).Length -le 64) -and (($CharacterTest.Match($TargetInfo.ZoneSetName[0]).Success)))
{
#Hold for future option
}
else
{
Write-Output " Invalid entry: ZoneSetName: $TargetInfo.ZoneSetName[0]"
Write-Output " Please correct this error in the data file and try again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
$TestLoop = 0
foreach ($TI in $TargetInfo)
{
if ($AllvHBAsA.Count -ne 0)
{
if ((($TI.NameA[$TestLoop]).Length -le 64) -and (($CharacterTest.Match($TargetInfo.NameA[$TestLoop]).Success)))
{
#Hold for future option
}
else
{