Windows 2008R2~2025安装NFS客户端的通用powershell代码(重启机器生效)

2024-09-12 10:33:36 浏览数 (3)

任何操作之前,先做快照以备不时之需回滚之便。

任何操作之前,先做快照以备不时之需回滚之便。

任何操作之前,先做快照以备不时之需回滚之便。

为了方便访问腾讯云NFS协议的CFS,Windows 2008R2~2025安装NFS客户端的通用powershell代码分享如下

重启机器生效,统一加了重启动作

重启机器生效,统一加了重启动作

重启机器生效,统一加了重启动作

代码语言:txt复制
#powershell管理员身份执行

#命令适用2008R2/2012R2/2016/2019/2022/2025

#重启机器生效,会重启机器的!!!最后一句代码就是重启机器!!!
#重启机器生效,会重启机器的!!!最后一句代码就是重启机器!!!
#重启机器生效,会重启机器的!!!最后一句代码就是重启机器!!!
代码语言:txt复制

$bufferSize = $Host.UI.RawUI.BufferSize
$bufferSize.Width = 1024
$Host.UI.RawUI.BufferSize = $bufferSize


$osInfo = Get-WmiObject -Class Win32_OperatingSystem
$osVersion = [version]$osInfo.Version

if ($osVersion -lt [version]"6.2") {
    # Windows Server 2008 R2 and older
    ServerManagerCmd -install FS-NFS-Services RSAT-NFS-Admin
} else {
    # Windows Server 2012 and newer
    Get-WindowsFeature NFS-Client,RSAT-NFS-Admin | Install-WindowsFeature
}


reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClientForNFSCurrentVersionDefault" /v AnonymousUid /t REG_QWORD /d 0 /f
reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClientForNFSCurrentVersionDefault" /v AnonymousGid /t REG_QWORD /d 0 /f
reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClientForNFSCurrentVersionUserDefaultMount" /v Locking /t REG_DWORD /d 0 /f

reg add "HKLMSYSTEMCurrentControlSetServicesLanmanWorkstationParameters" /v "AllowInsecureGuestAuth" /t REG_DWORD /d 1 /f
reg add "HKLMSYSTEMCurrentControlSetServicesLanmanWorkstationParameters" /v "RequireSecuritySignature" /t REG_DWORD /d 0 /f

net stop lanmanworkstation /y ; net start lanmanworkstation ; net start SessionEnv

reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClient for NFSCurrentVersionUsersDefaultCache" /v "AttributeTimeDelta" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClient for NFSCurrentVersionUsersDefaultCache" /v "FileAttributeCache" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftClient for NFSCurrentVersionUsersDefaultCache" /v "RemoteWriteCache" /d 0 /t REG_DWORD /f

reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesLanmanworkstationParameters" /v "FileInfoCacheLifetime" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesLanmanworkstationParameters" /v "FileNotFoundCacheLifetime" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesLanmanworkstationParameters" /v "DirectoryCacheLifetime" /d 0 /t REG_DWORD /f

shutdown -r -t 0

0 人点赞